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

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.
主站蜘蛛池模板: 垫江县| 宁南县| 彭州市| 蒙城县| 兴仁县| 石台县| 武冈市| 理塘县| 河曲县| 五指山市| 巴楚县| 沈阳市| 通榆县| 陆丰市| 拜城县| 盐亭县| 甘德县| 保定市| 苏尼特右旗| 石阡县| 梓潼县| 滕州市| 光泽县| 平陆县| 天镇县| 吐鲁番市| 紫阳县| 渭南市| 纳雍县| 衢州市| 涟源市| 桂阳县| 五原县| 工布江达县| 大悟县| 柳河县| 博湖县| 黄石市| 临汾市| 双峰县| 高雄县|