Hi,
I found this code that is supposed to enable user to enter a string of variable size from standard input by using istream_iterator. I understand how this works. Objects are extracted from an input stream and stored as string until end of file or some stream error is reached.
End of file is simulated by Ctrl-Z on Windows.Code:#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; int main () { vector<string> v; vector<string> ::const_iterator it; copy(istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(v)); for (it = v.begin(); it != v.end(); ++it) { cout<<*it<<" "; } }
I wonder how to make that input is finished either after user press Enter
(i.e. when newline is input stream) or when eof is reached.
Is it possible and how?
I've just started to learn about STL and I'm pretty new to the concept of iterators.
Thanks for help