I have a 2D vector and now I want to erase a certain row. I used vector.erase(myvec.begin()+temprow) temprow is the row number assuming that first row is 0[th] but should it be (myvec.begin()+temprow-1)
I want to see the erased row content to make sure . I tried to put it out on secreen but I couldn't do it.
I dont really know what a segfault is but when I use begin function it says (at the point before 'at' function) "no instance of overloaded function " and when I try to use front it says "no operator '+' matches these operands"
A segfault means youre accessing an invalid location or restricted location in memory. This can happen if you run over your array bounds or try to dereference something that doesnt have a proper place in memory.
you should be able to do pointer/iterator arithmetic but not reference arithmetic (as the reference is just a raw address and is not formatted with the type). I could be wrong though, I havent programmed c++ in a while. So thats why I think it complains about the '+' operator when you use the front() method.
What I believe is failing on the other statement is the at() function requires an int and not a reference to an object. But you could bypass that whole dilemma entirely by just dereferencing the iterator and sending it to standard out.
cout << (*(myvec.begin()+temprow));
so begin() returns an iterator which is a handy reference to an element. The * operator dereferences the iterator to obtain whatever is in that element. Now if im wrong about any of this I expect someone to properly ridicule and correct me.
@ slider57: Like cire said, OP probably uses a vector<vector<CustomClassThatDoesntAdd> > myvec; or something similar to have a "2D vector", and std::cout can't be fed an std::vector.