By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

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

P: n/a
I cant seem to find the problem in this code...

Expand|Select|Wrap|Line Numbers
  1. ifstream fin;
  2.     fin.open("C:/Users/Josh/Desktop/TriNode/NumList.txt");
  3.  
  4.     int first;
  5.     fin >> first;
  6.  
  7.     cout << first;
  8.  
  9.     if(first < 10)
  10.     {
  11.         trinode root(first);
  12.         list<int>::iterator currentIt;
  13.  
  14.         while(!fin.eof())
  15.         {
  16.             int temp;
  17.             fin >> temp;
  18.             root.insert_node(temp);
  19.         }
  20.     }
  21.  
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.
Oct 27 '10 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
list<int>::iterator 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.
Oct 27 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.