c++ 交换两个容器

#include <iostream>
#include <vector>
using namespace std;
int main ()
{
    vector<int> foo (3,100);   // three ints with a value of 100
    vector<int> bar (5,200);   // five ints with a value of 200
    
    foo.swap(bar);
    
    cout << "foo contains:";
    for (unsigned i=0; i<foo.size(); i++)
        cout << ' ' << foo[i];
    cout << '\n';
    
    cout << "bar contains:";
    for (unsigned i=0; i<bar.size(); i++)
        cout << ' ' << bar[i];
    cout << '\n';
    
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/10107744.html
今日推荐