Thread: Deleting vector parts?

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Deleting vector parts?

    (WinXp, Borland C++ Free command line)
    Ok, its come time I need to delete a nullified part of my vector.

    Heres my code summed up:

    Code:
    int main() {
     vector <int> X;
    
     x.push_back(1);
     x.push_back(2);
    
     x[1]=0;
     x.erase(x[1])
    }
    But my compiler doesnt like this at all.
    Code:
    Warning W8012 C:\PlatformClass.h 141: Comparing signed and unsigned values in function Platform::Fall()
    Error E2285 C:\MOPEngine.h 168: Could not find a match for 'vector<Platform,allocator<Platform> >::erase(Platform)' in function PlatBreaker()
    *** 1 errors in Compile ***
    
    C:\Borland\BCC55\Bin>
    I did a google search for this, and something about iterators or something poped up, but how do I return an iterator thats not the absolute beggining or absolute end of a vector? In this example it could work, but in my real code rend and rbegin wont work.

    So, how do I make this happy by giving it an iterator (that is what it wants right?)
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    ++iter

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Code:
    #include <iostream>
    #include <vector>
    
    void ShowContentsViaIterator(std::vector<int>& v)
    {
    std::vector<int>::iterator iter;
    
    for (iter=v.begin();iter!=v.end();++iter)
      {
      std::cout<<*iter<<std::endl;
      }
    }
    
    int main() {
     std::vector <int> x;
    
     x.push_back(1);
     x.push_back(2);
    
     x[1]=0;
     
     std::cout<<"Before erase:"<<std::endl;
     ShowContentsViaIterator(x);
     
     x.erase(x.begin()+1);
     
     std::cout<<"\nAfter erase:"<<std::endl;
     ShowContentsViaIterator(x);
    }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Lol, 7stud, that was probably the mosty helpful 1-word statement ever :P. Thank you guys very much!
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating and deleting directories and deleting files
    By fguy817817 in forum C Programming
    Replies: 1
    Last Post: 04-08-2009, 07:26 AM
  2. deleting nodes in a linear list
    By sudhanshu_nsit in forum C++ Programming
    Replies: 7
    Last Post: 06-25-2006, 02:00 AM
  3. Deleting dynamically allocated objects
    By Daniel Jurnove in forum C++ Programming
    Replies: 3
    Last Post: 11-07-2002, 03:30 AM
  4. Deleting Records from a structure
    By Simon in forum C Programming
    Replies: 5
    Last Post: 09-11-2002, 11:28 PM
  5. need help deleting a deleting a struct from file
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 05-20-2002, 05:38 AM