- 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.
推薦閱讀
- 計算機網絡
- PHP動態網站程序設計
- Learning Selenium Testing Tools with Python
- PostgreSQL技術內幕:事務處理深度探索
- Julia Cookbook
- Mastering ServiceNow(Second Edition)
- 軟件項目管理實用教程
- Arduino Wearable Projects
- Java程序設計實用教程(第2版)
- Sitecore Cookbook for Developers
- Node.js 6.x Blueprints
- 編程的原則:改善代碼質量的101個方法
- LabVIEW入門與實戰開發100例(第4版)
- Mastering R for Quantitative Finance
- 情境微課開發(第2版)