vector - STL C++

vector<X, A>::pop_back()

Declaration

void vector<X,A>::pop_back();

Description

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

Header Include

#include <vector>

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 vector before
	vector<char>::iterator qIter;
	cout << "Vector before = ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

	cout << "Pop off the last four entries" << endl;
	qV.pop_back();
	qV.pop_back();
	qV.pop_back();
	qV.pop_back();

	// Output the vector after
	cout << "Vector after = ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

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

Output

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

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