#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int> a = {1, 2, 3, 4, 5, 6};
//使用std::copy和std::ostream_iterator
ostream_iterator<int> output(cout, " ");
copy(a.begin(), a.end(), output);
cout << endl;
//使用for_each
for_each(a.begin(), a.end(), [](int val)
{ cout << val << " "; });
cout << endl;
}
c++打印容器元素的方法
最新推荐文章于 2025-01-29 13:44:42 发布