Thread: vector.pop_back() Question

  1. #1
    Registered User
    Join Date
    Apr 2009

    vector.pop_back() Question

    I am trying to remove an element from a vector, and I was told to use vector.pop_back(), but from the tutorial on this site, it claims the member function removes the last element. So if my vector.size() = 30, i.e., and I wanted to remove vector[12], how would my code look using .pop_back()?!? Thanks for the help!!

  2. #2
    Weak. dra's Avatar
    Join Date
    Apr 2005
    If the pop_back function removes the last element, then it wouldn't make sense to try and use it to remove an element that is somewhere in the middle. Use the erase member function instead.

    erase [C++ Reference]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM