- Mastering C++ Programming
- Jeganathan Swaminathan
- 105字
- 2021-07-02 18:28:50
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.
推薦閱讀
- 深入理解Android(卷I)
- Monkey Game Development:Beginner's Guide
- Big Data Analytics
- 實(shí)戰(zhàn)Java高并發(fā)程序設(shè)計(jì)(第3版)
- Unity 5 for Android Essentials
- Learning Unity 2D Game Development by Example
- Arduino家居安全系統(tǒng)構(gòu)建實(shí)戰(zhàn)
- 案例式C語(yǔ)言程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)
- Python程序設(shè)計(jì)與算法基礎(chǔ)教程(第2版)(微課版)
- Visual FoxPro 6.0程序設(shè)計(jì)
- 零基礎(chǔ)看圖學(xué)ScratchJr:少兒趣味編程(全彩大字版)
- Docker:容器與容器云(第2版)
- Python數(shù)據(jù)預(yù)處理技術(shù)與實(shí)踐
- Web開發(fā)新體驗(yàn)
- 第五空間戰(zhàn)略:大國(guó)間的網(wǎng)絡(luò)博弈