官术网_书友最值得收藏!

Commonly used vector APIs

The following table shows some commonly used vector APIs:

 

It would be really fun and convenient to read and print to/from the vector using istream_iterator and ostream_iterator. The following code demonstrates the use of a vector:

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;

int main () {
vector<int> v;

cout << "\nType empty string to end the input once you are done feeding the vector" << endl;
cout << "\nEnter some numbers to feed the vector ..." << endl;


istream_iterator<int> start_input(cin);
istream_iterator<int> end_input;

copy ( start_input, end_input, back_inserter( v ) );


cout << "\nPrint the vector ..." << endl;
copy ( v.begin(), v.end(), ostream_iterator<int>(cout, "\t") );
cout << endl;


return 0;
}

Note that the output of the program is skipped, as the output depends on the input entered by you. Feel free to try the instructions on the command line.
主站蜘蛛池模板: 凤山市| 河北省| 阿巴嘎旗| 克什克腾旗| 临夏县| 宁都县| 新营市| 全州县| 万全县| 凌云县| 新宾| 沭阳县| 昭平县| 固原市| 读书| 河津市| 天镇县| 榆树市| 宝山区| 绥滨县| 常熟市| 怀仁县| 盐亭县| 南溪县| 揭东县| 文成县| 锡林郭勒盟| 巨野县| 郑州市| 南宫市| 板桥市| 喜德县| 新丰县| 余姚市| 错那县| 金湖县| 尼木县| 杂多县| 株洲县| 宜春市| 赤峰市|