- 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.
推薦閱讀
- Learning Java Functional Programming
- Facebook Application Development with Graph API Cookbook
- Testing with JUnit
- Visual FoxPro程序設計教程
- 架構不再難(全5冊)
- Cross-platform Desktop Application Development:Electron,Node,NW.js,and React
- Learning Neo4j 3.x(Second Edition)
- 深度學習:算法入門與Keras編程實踐
- Getting Started with NativeScript
- Android開發:從0到1 (清華開發者書庫)
- Java EE 8 Application Development
- 現代C++編程實戰:132個核心技巧示例(原書第2版)
- 人人都能開發RPA機器人:UiPath從入門到實戰
- Learning GraphQL and Relay
- JavaScript程序設計基礎教程(慕課版)