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;

  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-03-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
  • 2021-10-18
相关资源
相似解决方案