example_13_8.cpp
来自「data+structures+using+c的源码」· C++ 代码 · 共 30 行
CPP
30 行
//STL functions fill and fill_n
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
int main()
{
vector<int> vecList(8); //Line 1
ostream_iterator<int> screen(cout, " "); //Line 2
fill(vecList.begin(), vecList.end(), 2); //Line 3
cout<<"Line 4: After filling vecList with 2's: "; //Line 4
copy(vecList.begin(), vecList.end(), screen); //Line 5
cout<<endl; //Line 6
fill_n(vecList.begin(), 3, 5); //Line 7
cout<<"Line 8: After filling the first three "
<<"elements with 5's: "<<endl<<" "; //Line 8
copy(vecList.begin(), vecList.end(), screen); //Line 9
cout<<endl; //Line 10
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?