Cpp中vector的输出打印

1. for

typedef vector<int> Vct;
Vct va;
va.push_back(1);
va.push_back(2);
va.push_back(3);

for(const int& k : va)
        cout << k << " ";
cout << endl;

2. for_each    声明在  #include <algorithm>

template <class T>
void show(const T& x)
{
    cout << x << " ";
}

for_each(va.begin(),va.end(),show<int>);
    cout << endl;

3. copy   声明在<algorithm>    ostream_iterator 在 <iterator>

#include <algorithm>
#include <iterator> // for ostream_iterator<>
copy(va.begin(),va.end(),ostream_iterator<int>(cout," "));
cout << endl;

  

 

posted @ 2019-05-18 16:58  htj10  阅读(1651)  评论(0编辑  收藏  举报
TOP