insertion_iterator.cpp
来自「C++ sample code, for the book: C++ blac」· C++ 代码 · 共 28 行
CPP
28 行
#include <iostream>
#include <string>
#include <iterator>
#include <vector>
using namespace std;
int main()
{
string string1[4] = {"This", "is", "a", "test"};
string string2[2] = {"not", "really"};
string string3[3] = {"yes", "it", "is"};
vector<string> text(4);
copy(string1, string1 + 4, text.begin());
ostream_iterator<string, char> out(cout, " ");
copy (text.begin(), text.end(), out);
cout << endl;
copy(string2, string1, insert_iterator<vector<string> >(text, text.begin() + 2));
copy (text.begin(), text.end(), out);
cout << endl;
copy(string3, string2, back_insert_iterator<vector<string> >(text));
copy (text.begin(), text.end(), out);
cout << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?