Hi. I'm a second-semester C++ student and am having quite a hard time with this assignment. The problem is:
Write a program that accepts strings from the console into a list and outputs them using iterators in alphabetical order.
Here's a snippet of the program so far. I figure that if I check if my current string (myString) is < the current position of the list (*pos), then I can .insert() myString into the list at that position. If it's not <, then the loop would just continue moving the pos iterator up until it does find a place where myString < *pos. However, this doesn't perform the insert if myString happens to be the LAST one in alphabetical order. I don't know how to continue with this 'bug'. Any help would be great.
In that case, I would suggest writing your own version of sort that sorts your container or string, then just using that. Of course your sort would use iterators (which is what they are intending for you to do I guess).
EDIT: Actually, hamsterman's idea is probably better if you do it right.
I don't know how to interpret this. Does it read, "if insert_my_string isn't done, push_back myList"? I don't see how I could implement that at the right point to have it work right.