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

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.
主站蜘蛛池模板: 梨树县| 视频| 闵行区| 阿瓦提县| 南涧| 安陆市| 斗六市| 和龙市| 盐山县| 蒲城县| 忻州市| 神木县| 越西县| 邹城市| 灵丘县| 旬阳县| 古田县| 萨嘎县| 五寨县| 西林县| 东阳市| 攀枝花市| 杭锦后旗| 泰和县| 东莞市| 凉山| 加查县| 宜春市| 吴江市| 阳高县| 大庆市| 来宾市| 临泽县| 依安县| 平舆县| 邹城市| 梁山县| 南城县| 鄂伦春自治旗| 黄梅县| 正定县|