vector - STL C++

vector<X, A>::reserve()

Declaration

void vector<X,A>::reserve(size_type qSize);

Description

This is the reserve() 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 capacity before and after the call to reserve()
	cout << "Vector capacity = " << qV.capacity() << endl;
	qV.reserve(34);
	cout << "Vector capacity = " << qV.capacity() << endl;

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

Output

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

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