qfedu-cpp-level/day9/stl_vector_demo/d5.cpp

29 lines
431 B
C++
Raw Normal View History

#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(vector<T> &v)
{
typename vector<T>::iterator it = v.begin();
while (it != v.end())
{
cout << *it << " ";
it++;
}
cout << endl;
}
int main()
{
int arr1[5] = {1, 2, 3, 4, 5};
vector<double> v1(arr1, arr1 + 5);
vector<double> v2(5, 1.2f);
v1.swap(v2);
print(v1);
print(v2);
return 0;
}