deque - STL C++

deque<X, A>::erase()

Declaration

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

Description

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

Header Include

#include <deque>

Overloads

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

Example

#include <iostream>
#include <deque>

int main()
{
	using namespace std;

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

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

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

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

Output

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

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