(1) Included in header file # include <iterator> (2) Use Istream_iterator and ostream_iterator like other iterator: Istream_iterator<string> start_cin (CIN); //input iterators point to standard input Istream_iterator<string> end_cin;when the input iterator is not pointing, it points to the end of the file by default (End-of-file)ostream_iterator<string> OS (cout, "\ n");//output iterator pointing to standard output(3) Read file data using Istream_iterator:
Ifstream fin ("data.txt"); Istream_iterator<int> Ibeg (Fin); 1 istream_iterator<int> iend; 2 vector<int> VI (Ibeg, iend); 3 //1 2 3 together: vector<int> VI ((istream_iterator<int> (Fin)), istream_iterator<int> ()); c10/>//output the data to the screen via the cout pointed to by Ostream_iterator: copy (Vi.begin (), Vi.end (), ostream_iterator<int> (cout, "\ n") );
C + + Stream_iterator