vector function erase

hi,

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.

cout<<myvec.at(myvec.begin()+temprow);
cout<<myvec.at(myvec.front()+temprow);

these didn't work
how can I see it on screen?
Did you get a segfault when you tried to display 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"
vector::begin() returns a vector::iterator.
vector::at() needs an unsigned integer.
vector::front() returns the first element in the vector.

Does whatever type you store in myvec support addition to whatever type temprow is?

Anyway, here's an article that may be useful:
http://www.cplusplus.com/articles/NAUq5Di1/
Last edited on
And, of course, cout doesn't know how to insert a vector into the standard output stream.
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.
Topic archived. No new replies allowed.