Link list Iterator.

Hi,
I started writing a program that takes a name and put it in a list (created in the program) by alphabetical order. I almost finish it. But I can't figure out how to compare the string with other strings in the list and insert it at the right position. Here is my code so far. Please help me out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
void main(){
	list<string> myList;
	string myString;

	myList.push_back("Bob");
	myList.push_back("Julia");
	myList.push_back("Kim");

	list<string>::iterator iter = myList.begin();


	for(; iter != myList.end(); iter++)
	{
		cout << *iter << endl;
	}

	cout << "Please enter a word name " << endl;
	cin >> myString ;
	cout << endl;


	for(list<string>::iterator pos= myList.begin(); pos!=myList.end(); pos++){
		string currentValue = *pos;
		if(myString.compare(*pos)!=0){
			//do something
		}	
		else
			//insert the string???
			
	}
Topic archived. No new replies allowed.