vector - STL C++

vector<bool, A>::swap()

Declaration

vector<bool, A>::swap();

Description

This the swap() function for the vector class template specialization of the bool type, which swaps the entries of one vector with another.

Header Include

#include <vector>

Example

#include <iostream>
#include <vector>

int main()
{
	using namespace std;

	// Create a two vector instances and add bits to them
	vector<bool> qV1;
	qV1.push_back(true);
	qV1.push_back(false);
	qV1.push_back(false);
	qV1.push_back(true);

	vector<bool> qV2;
	qV2.push_back(false);
	qV2.push_back(true);

	// Output the vectors and the swapped version
	for (int i = 0; i < 2; ++i) {
		cout << "V1  = ";
		vector<bool>::iterator qIter;
		for (qIter = qV1.begin(); qIter != qV1.end(); ++qIter) {
			cout << *qIter;
		}
		cout << endl;
		cout << "V2  = ";
		for (qIter = qV2.begin(); qIter != qV2.end(); ++qIter) {
			cout << *qIter;
		}
		cout << endl;
		if (i == 0) {
			cout << "swap vectors" << endl;
		}
		qV1.swap(qV2);
	}

	cin.get();
	return 0;
}

Output

vector<bool, A>::swap() Output
 

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