Could someone please explain why the first code snippet inserts properly into a list and the second code snippet does not. The position of the bold expressions are the only differences. iter, s and LS were declared elsewhere in main().
snippet 1.)
snippet 2.)
thanks in advance.
snippet 1.)
Code:
while (true) {
cout << "Enter string (ENTER to exit): ";
getline(cin, s);
if (s.size() == 0)
break;
for(iter=LS.begin();iter != LS.end() && s > *iter; )
[B]iter++;[/B]
LS.insert(iter, s);
}
Code:
while (true) {
cout << "Enter string (ENTER to exit): ";
getline(cin, s);
if (s.size() == 0)
break;
//LS.push_back(s);
for(iter=LS.begin();iter != LS.end() && s > *iter; [B]iter++[/B])
LS.insert(iter, s);
}
Comment