views:

165

answers:

2

I am trying to learn more about list containers and how to iterate through them, but it seems that g++ has no problem with it, but Visual Studio C++ pukes all over the place!

#include <iostream>
#include <string>
#include <list>

using namespace std;

int main(){

   list <string> data;
   list <int>::iterator it;

   data.push_back("fee");
   data.push_back("fi");
   data.push_back("foo");
   data.push_back("fum");

   // something breaks back here ?!?!
  for(it=data.begin(); it!=data.end(); it++){
     cout << *it << endl;
  }

  return 0;

}
+16  A: 

Try

list<string>::iterator

instead of

list<int>::iterator.
Adam Mitz
Man, that was dumb of me! thanks!
gjohnson
You're welcome. On StackOverflow you can express your thanks by selecting this answer (or Jesse's) as the "accepted answer".
Adam Mitz
+12  A: 

gcc should "puke" here too (it does for me). You're assigning a list<string>::iterator to a list<int>::iterator, which are different types.

Jesse Beder