vector - STL C++

vector<X, A>::capacity()

Declaration

size_type vector<X,A>::capacity();

Description

This is the capacity() 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;
	// Add each entry with a call to capacity to show size changes
	cout << "Capacitity = " << qV.capacity() << endl;
	qV.push_back('X');
	cout << "Capacitity = " << qV.capacity() << endl;
	qV.push_back('o');
	cout << "Capacitity = " << qV.capacity() << endl;
	qV.push_back('a');
	cout << "Capacitity = " << qV.capacity() << endl;
	qV.push_back('X');
	cout << "Capacitity = " << qV.capacity() << endl;
	qV.push_back('.');
	cout << "Capacitity = " << qV.capacity() << endl;
	qV.push_back('n');
	cout << "Capacitity = " << qV.capacity() << endl;
	qV.push_back('e');
	cout << "Capacitity = " << qV.capacity() << endl;
	qV.push_back('t');
	cout << "Capacitity = " << qV.capacity() << endl;

	// Output the entries
	vector<char>::iterator qIter;
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

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

Output

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

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