I am trying to insert a new element into a vector in C++ under Ubuntu Linux.
The following is what I did, where v contain some element already. InsertElementNo is the element number the new content "entry" should be inserted.
For example:
v contains "Test,Is,Good"
If entry = "Lord" and InsertElementNo = 2,
After v.insert v should look like "Test,Lord,Is,Good"
However the above code gives me "segmentation error".Code:vector <string> v; vector <string>::iterator pos = v.begin(); ....... v.insert(pos+(InsertElementNo-1), entry);
Couldn't figure out why.



LinkBack URL
About LinkBacks



