Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-03-2010
Member
 
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!!!
Reply With Quote
  #2  
Old 12-03-2010
Member
 
Join Date: May 2008
Posts: 2,383
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 );
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 12-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #4  
Old 12-03-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
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
Reply With Quote
  #5  
Old 12-03-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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.
Reply With Quote
  #6  
Old 12-03-2010
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use an erase() in C++"
Thread Thread Starter Forum Replies Last Post
Erase an SSD before returning it ADALBERTO Portable Devices 6 03-07-2010 06:06 AM
Erase an SSD before returning it Chen Operating Systems 6 03-07-2010 04:01 AM
Not able to erase the RW DVD using the LG DVD Drive Emiliio Hardware Peripherals 5 13-01-2010 01:22 PM
How can i erase a DVR tape Kamran Windows Software 3 28-05-2009 11:37 AM
How Can I erase CD-RW & DVD-RW BoanHed Windows XP Support 3 10-03-2007 08:49 PM


All times are GMT +5.5. The time now is 07:28 PM.