Why is there an error

for (int i = 0; i<fav_games.end(); ++i)
{
cout<<fav_games[i]<<"\n";
}
return 0;

There seems to be an error under the '<' in 'i<fav_games.end();'
Why??!!
closed account (zb0S216C)
If "end( )" is a member of a standard container of some-sort, then "end( )" will return an iterator[1] to the end of the container, and not an integer. Here's how you should use it properly:

1
2
for(container_name<type>::iterator i(fav_games.begin( )); i < fav_games.end( ); ++i)
    std::cout << *i << '\n';

References:
[1] http://www.cplusplus.com/reference/std/iterator/


Wazzak
Last edited on
Thanks a lot man, stupid mistake ahaha
Topic archived. No new replies allowed.