vector - STL C++

vector<X, A>::back()

Declaration

reference vector<X,A>::back();

Description

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

Header Include

#include <vector>

Overloads

const_reference vector<X,A>::back() const;

Example

#include <iostream>
#include <vector>

int main()
{
	using namespace std;

	// Create two vector instances
	vector<int> qV1;
	qV1.push_back(3);
	qV1.push_back(4);

	vector<int> qV2;
	qV2.push_back(9);
	qV2.push_back(7);

	// Get references to the last entries
	int& irIntRef = qV1.back();
	const int& kirConstIntRef = qV2.back();

	cout << "The last entry of V1 = " << irIntRef << endl;
	cout << "The last entry of V2 = " << kirConstIntRef << endl;

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

Output

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

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