0

i'm trying to read from a text file and store it into a STL List. i able to read from the file but when i wanted to print out my list i get an error - primary-expression before '>' token which is pointed to the text in red. am i doing it wrongly?

fin >> list;
    if(list != "//")
    {
       cout << list << endl;
       myList.push_back(list);
       list<string>::iterator p = myList.begin();
       
       while(p != myList.end())
       {
          cout << *p;
          p++;
       }
    }
2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

The problem is that you have re-used the name list to be something other than std::list. When you do that the compiler gets confused. Name that variable something else, such as

fin >> word;
    if(word != "//")
    {
       cout << line << endl;
       myList.push_back(word);
       list<string>::iterator p = myList.begin();
       
       while(p != myList.end())
       {
          cout << *p;
          p++;
       }
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.