can I get some feedback on why this IF statement is failing me?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jonah Portas

    #1

    can I get some feedback on why this IF statement is failing me?

    I cant seem to find the problem in this code...

    Code:
    ifstream fin;
    	fin.open("C:/Users/Josh/Desktop/TriNode/NumList.txt");
    
    	int first;
    	fin >> first;
    
    	cout << first;
    
    	if(first < 10)
    	{
    		trinode root(first);
    		list<int>::iterator currentIt;
    
    		while(!fin.eof())
    		{
    			int temp;
    			fin >> temp;
    			root.insert_node(temp);
    		}
    	}
    when I try to use the trinode "root" or the iterator "currentIt" after this if statement, it keeps giving me errors saying they are not declared, which I would assume means it never gets past the IF(first <10) but If i cout << first right before, its 8.....which is obviously less than 10. If i remove the if statement it will work..but i NEED that statement for later code.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    list<int>::iter ator currentIt is a local variable in the if statement. It goes out of scope when you leave the if statement.

    If you need it outside the if statement, then define it outside the if statement.

    Comment

    Working...