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++;
       }
    }

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++;
       }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.