I feel like I might be overlooking something very extremely simple here, but I have made some code just to test out insert / splice on lists and I am getting a seg-fault on the code I made. Can someone tell me where / why?
#include <iostream>
#include <vector>
#include <list>
using namespace std;
int main(){
vector <int> iVec;
list <int> iList;
vector<int>::iterator vIt;
list <int>::iterator lIt;
for(int i = 0; i < 10; i++){
iVec.push_back(i*10);
iList.push_back(i*10);
}//0, 10, 20, 30....90
//0 <-- current pos of iterator lIt
lIt++;
lIt++;
//0, 10, 20
iList.insert(lIt, 3);
//Vector output loop
for(vIt = iVec.begin(); vIt!= iVec.end(); vIt++){
}
cout << endl << endl <<"List Contents: " <<endl << endl;
//List output loop
for(lIt = iList.begin(); lIt != iList.end(); lIt++){
cout << *lIt << endl;
}
return 0;
}
lIthas not been correctly initialized – it is an iterator – but currently does not point to anything – you need to do this: