- Mastering C++ Programming
- Jeganathan Swaminathan
- 136字
- 2021-07-02 18:28:50
Code walkthrough
Basically, the copy algorithm accepts a range of iterators, where the first two arguments represent the source and the third argument represents the destination, which happens to be the vector:
istream_iterator<int> start_input(cin);
istream_iterator<int> end_input;
copy ( start_input, end_input, back_inserter( v ) );
The start_input iterator instance defines an istream_iterator iterator that receives input from istream and cin, and the end_input iterator instance defines an end-of-file delimiter, which is an empty string by default (""). Hence, the input can be terminated by typing "" in the command-line input terminal.
Similarly, let's understand the following code snippet:
cout << "\nPrint the vector ..." << endl;
copy ( v.begin(), v.end(), ostream_iterator<int>(cout, "\t") );
cout << endl;
The copy algorithm is used to copy the values from a vector, one element at a time, to ostream, separating the output with a tab character (\t).
推薦閱讀
- ExtGWT Rich Internet Application Cookbook
- Java技術手冊(原書第7版)
- Wireshark Network Security
- PHP+MySQL+Dreamweaver動態網站開發實例教程
- C語言程序設計學習指導與習題解答
- 飛槳PaddlePaddle深度學習實戰
- Test-Driven Development with Django
- FPGA嵌入式項目開發實戰
- Web App Testing Using Knockout.JS
- 單片機原理及應用技術
- 超簡單:用Python讓Excel飛起來(實戰150例)
- iOS開發項目化入門教程
- Java 9 with JShell
- Python繪圖指南:分形與數據可視化(全彩)
- 高性能MVVM框架的設計與實現:San