vector - STL C++

vector<X, A>::get_allocator()

Declaration

A vector<X,A>::get_allocator() const;

Description

This is the get_allocator() 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<int> qV;

	vector<int>::allocator_type qAlloc = qV.get_allocator();
	// Use the allocator to allocate an array of three ints
	allocator<int>::pointer qPtr = qAlloc.allocate(3);
	qPtr[0] = 8;
	qPtr[1] = 4;
	qPtr[2] = 2;
	// Output the three ints in the allocate array
	for (int iIndex = 0; iIndex < 3; ++iIndex) {
		cout << qPtr[iIndex] << "  ";
	}
	cout << endl;
	// Deallocate the array
	qAlloc.destroy(qPtr);

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

Output

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

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