E
Eric Lilja
Consider the following code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int
main()
{
vector<string> wl;
vector<string>::iterator it = wl.begin();
string w;
while(cin >> w)
{
wl.insert(it++, w);
cout << "inserted successfully" << endl;
}
}
It crashes after one succesful insert it seems. I know I can solve it
using push_back or push_front, but I'm looking at a bigger program that
uses inserts exclusively and doesn't crash...In the real program I dont
want to add elements to the front or the back
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int
main()
{
vector<string> wl;
vector<string>::iterator it = wl.begin();
string w;
while(cin >> w)
{
wl.insert(it++, w);
cout << "inserted successfully" << endl;
}
}
It crashes after one succesful insert it seems. I know I can solve it
using push_back or push_front, but I'm looking at a bigger program that
uses inserts exclusively and doesn't crash...In the real program I dont
want to add elements to the front or the back