Results 1 to 6 of 6

Thread: How to use an erase() in C++

  1. #1
    Join Date
    Dec 2009
    Posts
    28

    How to use an erase() in C++

    I am studying in the BSC-IT. I had learned the C++ language. I can also have the knowledge of the working of the functions. So, I want to know about the erase() function of the C++ language. I also want to know about How to use the erase() function of the C++ language. Can anyone help me to know about the erase() function of the C++ language, Reply Me!!!

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: How to use an erase() in C++

    The erase() function of the C++ language can be use to remove from the given specified vector class that can be an either a single element or a range of an elements such as ([fst,lst)). The following can be the general form of the push_back() function in the C++ language as :
    Code:
    iterator erase ( itrtr pstn );
    iterator erase ( itrtr fst, itrtr lst );

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to use an erase() in C++

    The form of the erase() function that can be used in the C++ language can be as follows :
    1. fst, lst : The fst and lst parameters can consist an iterators that can be specifying given a range within the vector that can be deleted.
    2. pstn : This parameters of the erase() function can contains an iterator that can be pointing to a single an element that can be deleted from the given specified vector.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to use an erase() in C++

    I can suggest you that to carefully go through the following code of lines that can demonstrates you how to use the erase() function in the C++ programming as follows :
    Code:
    #include <iostream>
    #include <vector>
    using namespace std;
    int main ()
    {
      unsigned gnt g;
      vector<unsigned int> mvctr;
      for (g=1; g<=10; g++) mvctr.push_back(g);
      mvctr.erase (mvctr.begin()+5);
      mvctr.erase (mvctr.begin(),mvctr.begin()+3);
      cout << "mvctr contains:";
      for (g=0; g<mvctr.size(); g++)
        cout << " " << mvctr[g];
      cout << endl;
      return 0;
    }
    Output:
    Code:
    mvctr contains: 4 5 7 8 9 10

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to use an erase() in C++

    The erase() function removes an element at given specified location lc or removes an elements that can be between strt and nd. The erase() function can returns the value of an element after the end element that can be erased. The first version of an erase can be executed in the constant time for the lists and linear time for the given specified vectors, dequeues, and strings. The multiple-element version of erase always takes linear time.

  6. #6
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to use an erase() in C++

    The erase() function of the C++ language can be used to erase an element of the vector. The code of lines that can be defined below help's you to learn about the erase() function of the C++ language :
    Code:
    #include <iostream>
    #include <vector>
    #include <itrator>
    using namespace std;
    int main()
    {
        vector<char> alps;
        for( int l=0; l < 10; l++ ) 
    {
          static const char ltrs[] = "ABCDEFGHIJ";
          alps.push_back( ltrs[l] );
        }
        vector<char>::itrator itr = alps.begin();
        while( itr != alps.end() )
        {
          if (*itr == 'B' || *itr == 'D')
            itr = alps.erase( itr );
          else
            ++itr;
        }
        copy(alps.begin(), alps.end(), ostream_itrator<char>(cout, ""));
        cout << endl;
    }
    When run, the above code displays:
    Code:
        ACEFGHIJ

Similar Threads

  1. Erase an SSD before returning it
    By ADALBERTO in forum Portable Devices
    Replies: 6
    Last Post: 03-07-2010, 06:06 AM
  2. Erase an SSD before returning it
    By Chen in forum Operating Systems
    Replies: 6
    Last Post: 03-07-2010, 04:01 AM
  3. Not able to erase the RW DVD using the LG DVD Drive
    By Emiliio in forum Hardware Peripherals
    Replies: 5
    Last Post: 13-01-2010, 01:22 PM
  4. How can i erase a DVR tape
    By Kamran in forum Windows Software
    Replies: 3
    Last Post: 28-05-2009, 11:37 AM
  5. How Can I erase CD-RW & DVD-RW
    By BoanHed in forum Windows XP Support
    Replies: 3
    Last Post: 10-03-2007, 08:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,717,836.59382 seconds with 17 queries