function to print a list <solved>

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
In Line 5 you are missing cout << before endl;
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
Use
list<string>::const_iterator i;

instead. That will fix your compile error.
Topic archived. No new replies allowed.