Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

johnnyBravo

vectors, how to remove parts of the array?

This topic is 5426 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

say ive got:
vector <int> number;
number.push_back(0);
number.push_back(1);
number.push_back(2);
number.push_back(3);
number.push_back(4);
how would i remove number 2? that is number[2] Thanks,

Share this post


Link to post
Share on other sites
Advertisement
If you only have one element in the array then removing the element at index 2 doesn''t make very much sense.

Share this post


Link to post
Share on other sites
If you routinely remove elements from the front, and don''t need contiguous storage, use a deque instead of a vector, and call pop_front().

Share this post


Link to post
Share on other sites
quote:
Original post by Nervo
when you erase the element do cout << number.size();

and see what it tells you.
Learn to use your debugger instead of littering your code with cout statements. (Yes, you can''t display the contents of Standard Library containers in the debugger in VC6 - natively; expand them and look at their internal data structures.)

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane
"Doesn''t seem to work" is rather vague.


You should be used to that answer by now.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!