vector - STL C++

vector<X, A>::erase()

Declaration

iterator vector<X,A>::erase(const_iterator qIter);

Description

This is the erase() function for the vector class template.

Header Include

#include <vector>

Overloads

iterator vector<X,A>::erase(const_iterator qStart, const_iterator qEnd);

Example

#include <iostream>
#include <vector>

int main()
{
	using namespace std;

	// Create a vector instance
	vector<char> qV;
	qV.push_back('X');
	qV.push_back('o');
	qV.push_back('a');
	qV.push_back('X');
	qV.push_back('.');
	qV.push_back('n');
	qV.push_back('e');
	qV.push_back('t');

	// Output the entries after we erase the 'n'
	vector<char>::iterator qIter = qV.begin();
	qIter += 5;
	qV.erase(qIter);
	cout << "V = ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

	// Output the entries after we erase the last three entries
	qIter = qV.begin();
	qIter += 4;
	qV.erase(qIter, qV.end());
	cout << "V = ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

vector<X, A>::erase() Output
 

© 2007–2025 XoaX.net LLC. All rights reserved.