vector - STL C++

vector<X, A>::operator=()

Declaration

vector<X,A>& vector<X,A>::operator=(const vector<X,A>& kqrVector);

Description

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

Header Include

#include <vector>

Overloads

vector<X,A>& vector<X,A>::operator=(vector<X,A>&& qrrVector);

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

	vector<char> qCopy;
	qCopy.push_back('A');
	qCopy.push_back('B');
	qCopy.push_back('C');

	// Output the vector before the assignment
	vector<char>::iterator qIter;
	cout << "Vector before = ";
	for (qIter = qCopy.begin(); qIter != qCopy.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

	cout << "Copy the vector with the assignment operator" << endl;
	qCopy = qV;

	// Output the vector after the assignment
	cout << "Vector after = ";
	for (qIter = qCopy.begin(); qIter != qCopy.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

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

Output

vector<X, A>::operator=() Output
 

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