vector - STL C++

vector<X, A>::front()

Declaration

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

Description

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

Header Include

#include <vector>

Overloads

const_reference vector<X,A>::front() 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 first entries
	int& irIntRef = qV1.front();
	const int& kirConstIntRef = qV2.front();

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

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

Output

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

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