J
Jess
Hello,
When I copy contents from an input string to a vector, I typically use
something like this
vector<string> v;
ifstream in("file");
copy(istream_iterator<string> (in), istream_iterator<string>(),
back_inserter(v));
However, I also tried to define istream_iterator separately. I did
istream_iterator<string> it(in);
this works, but there's no way I can define something equivalent to
istream_iterator<string>() above. I tried
istream_iterator<string> it;
and this failed. What does "istream_iterator<string>()" mean? Does
it define an iterator that's not bound to any istream? If so, why my
code above "istream_iterator<string> it;" doesn't work?
There are some error-detection functions, such as "bad(), "good()",
"fail()". I'm not sure what constitutes "errors". If I read from a
file and hit the end of the file, does it leave the stream in an error
state? If the reading reaches EOF, then do I need to use "clear()" to
reset it? If I use "clear()" to reset a stream (for whatever error
reasons), are the remaining data on the stream lost?
Thanks a lot!
Jess
When I copy contents from an input string to a vector, I typically use
something like this
vector<string> v;
ifstream in("file");
copy(istream_iterator<string> (in), istream_iterator<string>(),
back_inserter(v));
However, I also tried to define istream_iterator separately. I did
istream_iterator<string> it(in);
this works, but there's no way I can define something equivalent to
istream_iterator<string>() above. I tried
istream_iterator<string> it;
and this failed. What does "istream_iterator<string>()" mean? Does
it define an iterator that's not bound to any istream? If so, why my
code above "istream_iterator<string> it;" doesn't work?
There are some error-detection functions, such as "bad(), "good()",
"fail()". I'm not sure what constitutes "errors". If I read from a
file and hit the end of the file, does it leave the stream in an error
state? If the reading reaches EOF, then do I need to use "clear()" to
reset it? If I use "clear()" to reset a stream (for whatever error
reasons), are the remaining data on the stream lost?
Thanks a lot!
Jess