#include <iostream>
#include <vector>
using namespace std;
template <typename T>
void display_vector(const vector<T> &vec);
int main()
{
vector<int> ivec1, ivec2;
ivec1 = { 1, 2, 3 };
ivec2 = { 4, 5, 6 };
//ivec1.assign(ivec2.begin(), ivec2.end());
swap(ivec1, ivec2);
cout << "ivec1: " << endl;
display_vector(ivec1);
cout << "\nivec2: " << endl;
display_vector(ivec2);
return 0;
}
template <typename T>
void display_vector(const vector<T> &vec)
{
for (auto val : vec)
cout << val << " ";
cout << endl;
}
swap demo
最新推荐文章于 2024-01-28 11:30:00 发布