vector - STL C++

vector<X, A>::operator[]()

Declaration

reference vector<X,A>::operator[](size_type qIndex);

Description

This is the operator[]() function for the vector class template.

Header Include

#include <vector>

Overloads

const_reference vector<X,A>::operator[](size_type qIndex) const;

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');

	// Use the array operator to access elements
	for (int iIndex = 0; iIndex < 8; ++iIndex) {
		cout << qV[iIndex];
	}
	cout << endl;

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

Output

vector<X, A>::operator[]() Output
 

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