Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. STL

STL

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphics
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 4315
    wrote on last edited by
    #1

    Hi, I have a vector object that has some elements in it and I want to remove an item completly from the vector. Here is what I mean, vector inV; for (i=0; i<10; i++) inV.push_back(i); I would like to call a function that will remove one of the items and leave me with 9 elements in the vector. I tried using remove(...), but that doesn't do what I want. If I use remove, I have to copy the valid elements from one vector to another and I don't really want to do that each time I have to delete an element. If this is possible please let me know. Thank in advance

    U 1 Reply Last reply
    0
    • U User 4315

      Hi, I have a vector object that has some elements in it and I want to remove an item completly from the vector. Here is what I mean, vector inV; for (i=0; i<10; i++) inV.push_back(i); I would like to call a function that will remove one of the items and leave me with 9 elements in the vector. I tried using remove(...), but that doesn't do what I want. If I use remove, I have to copy the valid elements from one vector to another and I don't really want to do that each time I have to delete an element. If this is possible please let me know. Thank in advance

      U Offline
      U Offline
      Uwe Keim
      wrote on last edited by
      #2

      what about using the std::vector::erase() function to delete a single element or the std::vector::clear() function to remove 'em all?

      U 1 Reply Last reply
      0
      • U Uwe Keim

        what about using the std::vector::erase() function to delete a single element or the std::vector::clear() function to remove 'em all?

        U Offline
        U Offline
        User 4315
        wrote on last edited by
        #3

        Hi Uwe, I think I can use erase() to delete a single element. I know there had to be an easier way, thanks allot.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups