I'm just wondering how the program presented at the end of the tutorial knows when to stop accepting words from the standard input.
Code:
// This vector of strings will be holding the words as the user
// enters them.
vector<string> words;
// std::ostream_iterator's evil twin, std::istream_iterator, can
// be used for doing the opposite: turn an input stream into an
// iterator. Here we keep copy all strings from cin to the back of
// the words vector:
copy (istream_iterator<string> (cin),
istream_iterator<string> (), // "end"
back_inserter (words));
This is the code that I don't really understand. When I compile the program and run it I can enter an infinite number of words without the program printing the list of words.
Maybe I just don't understand iterators enough.
Code:
istream_iterator();
Construct an end-of-stream iterator. This iterator can be used to
compare against an end-of-stream condition. Use it to provide end
iterators to algorithms
This is from
http://h30097.www3.hp.com/cplus/istr...or_3c__std.htm
It seems that I just don't know how to close the stream?