From: http://zhidao.baidu.com/question/293245134.html? Fr = qrl & cid = 93 & Index = 3
On Windows, generally, the input of the simulated EOF is Ctrl + Z at the beginning of a new line. In UNIX, enter Ctrl + D at the beginning of a new line.
Attached:
// Three sentences are used to input words on the screen, sort words in alphabetical order, remove duplicate words, and output to the screen. Vector <string> V1 (istream_iterator <string> (CIN), (istream_iterator <string> (), sort (v1.begin (), v1.end ()); // cout <"\ n out: \ n"; unique_copy (v1.begin (), v1.end (), ostream_iterator <string> (cout, ""); Explanation from:
http://blog.csdn.net/sandy_zc_1/article/details/6529304
With STL implementation, there are exactly three lines of code. To explain a little: the first sentence defines a vector V1 and passes in two input stream iterators In the constructor. These two iterators constitute a range that represents all input words, until the input ends (EOF ). In this way, V1 fills up all input words during creation. Second, use sort to sort the elements in the vector. Yes, you do not need to write complex string comparison functions. Strings contain operator <definitions. Sort only requires a smaller number to operate. After sorting, all words are sorted in alphabetical order. Third, use unique_copy to copy data in V1 to the target range. The difference between unique_copy and copy is that it can remove N consecutive identical elements, leaving only one element to implement unique. The starting point of the target range of this copy is the stream iterator. This is the output stream iterator, which outputs the data from the algorithm to the cout, so it is displayed on the screen. It's amazing. It's powerful. I think it is quite good to use this example as the end of the introduction of the iterator adapter.