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;
常记溪亭日暮,沉醉不知归路。兴尽晚回舟,误入藕花深处。争渡,争渡,惊起一滩鸥鹭。
昨夜雨疏风骤,浓睡不消残酒。试问卷帘人,却道海棠依旧。知否?知否?应是绿肥红瘦。
浙公网安备 33010602011771号