void vector<X,A>::swap(vector<X,A>& qrVector) const;
#include <vector>
#include <iostream>
#include <vector>
int main()
{
using namespace std;
// Create two vector instances
vector<char> qV1;
qV1.push_back('X');
qV1.push_back('o');
qV1.push_back('a');
qV1.push_back('X');
qV1.push_back('.');
qV1.push_back('n');
qV1.push_back('e');
qV1.push_back('t');
vector<char> qV2;
qV2.push_back('S');
qV2.push_back('T');
qV2.push_back('L');
// Output the vectors and the swapped versions
for (int i = 0; i < 2; ++i) {
cout << "V1 = ";
vector<char>::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);
}
// Keep the window open
cin.get();
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.