Oct 22, 2008 at 2:25pm
Hi I have some problems making a function that can print out some different lists. In main() I can do this with:
1 2 3 4
|
list<string>::iterator i;
for( i = a1.begin(); i != a1.end(); ++i)
cout << *i << " ";
cout << endl;
|
But when I use the same in my function print() I get a error:
1 2 3 4 5
|
void print(const list<string>& s) {
list<string>::iterator i;
for( i = s.begin(); i != s.end(); ++i)
cout << *i << " ";
endl;
|
Any help is really appreciated. I'm stuck!
Last edited on Oct 23, 2008 at 8:29am
Oct 22, 2008 at 2:34pm
In Line 5 you are missing cout << before endl;
Oct 22, 2008 at 2:37pm
Sry I had changed it.. And I still got an error??
1 2 3 4 5 6
|
void print(const list<string>& s) {
list<string>::iterator i;
for( i = s.begin(); i != s.end(); ++i)
cout << *i << " ";
cout << endl;
}
|
And the error message is pretty meaningless for me..
Last edited on Oct 22, 2008 at 2:38pm
Oct 22, 2008 at 2:45pm
Use
list<string>::const_iterator i;
instead. That will fix your compile error.