vector - STL C++

vector<X, A>::emplace_back()

Declaration

void vector<X,A>::emplace_back(X&& xrrValue);

Description

This is the emplace_back() 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 entries, call emplace_back and output them again
	vector<char>::iterator qIter;
	cout << "V = ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;
	// Call emplace_back
	cout << "call emplace_back()" << endl;
	qV.emplace_back('Z');
	cout << "V = ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

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

Output

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

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