eg.
vector<char> alphas;
for( int i=0; i < 10; i++ ) {
static const char letters[] = "ABCDEFGHIJ";
alphas.push_back( letters[i] );
}
vector<char>::size_type size = alphas.size();
vector<char>::iterator startIterator;
vector<char>::iterator tempIterator;
for( vector<char>::size_type i=0; i < size; i++ ) {
startIterator = alphas.begin();
alphas.erase( startIterator );
// Display the vector
for( tempIterator = alphas.begin(); tempIterator != alphas.end(); ++tempIterator ) {
cout << *tempIterator;
}
cout << endl;
}
output:
BCDEFGHIJ
CDEFGHIJ
DEFGHIJ
EFGHIJ
FGHIJ
GHIJ
HIJ
IJ
J
vector<char> alphas;
for( int i=0; i < 10; i++ ) {
static const char letters[] = "ABCDEFGHIJ";
alphas.push_back( letters[i] );
}
// display the complete vector
for( vector<char>::size_type i = 0; i < alphas.size(); i++ ) {
cout << alphas[i];
}
cout << endl;
// use erase to remove all but the first two and last three elements
// of the vector
alphas.erase( alphas.begin()+2, alphas.end()-3 );
// display the modified vector
for( vector<char>::size_type i = 0; i < alphas.size(); i++ ) {
cout << alphas[i];
}
cout << endl;
output:
ABCDEFGHIJ
ABHIJ
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
int main()
{
vector<char> alphas;
for( int i=0; i < 10; i++ ) {
static const char letters[] = "ABCDEFGHIJ";
alphas.push_back( letters[i] );
}
vector<char>::iterator iter = alphas.begin();
while( iter != alphas.end() )
{
if (*iter == 'B' || *iter == 'D')
iter = alphas.erase( iter );
else
++iter;
}
copy(alphas.begin(), alphas.end(), ostream_iterator<char>(cout, ""));
cout << endl;
}
output :
ACEFGHIJ