Hi you all,
I have a part of a code that I'm trying to understand. The program lets you put in a start and a end time(hh:mm), and then calculate a price depending on the total time. The part that I don't understand is this. Could someone please explain it as if I were 5(eli5).
1 2 3 4 5 6
istringstream iss(start);
iss >> startHour >> startMinute;
iss.clear();
iss.str(end);
iss >> endHour >> endMinute;
istringstream iss(start);
istringstream object iss constructed with string object start via default istringstream ctor
iss >> startHour >> startMinute;
iss does not read whitespace, so iss until first whitespace is read into int startHour, then whitespace skipped and the second sequence read into int startMinute. If the string start does not match this sequence iss will fail
iss.clear();
done reading, so iss is cleared for next read ... as below ..
iss.clear();
done reading, so iss is cleared for next read ... as below ..
No, the clear() clears any error flags, it doesn't erase the stream contents.
This: iss.str(end); sets (copies) the string "end" to be the source for the iss stream.
Yes I did, but didn't understand much of that either.
Then you need to either find more documentation, documentation that you understand, or perhaps change professions. If you can't read and understand documentation for the standard C++ classes you're not going to have much luck becoming a C++ programmer, IMO.
Note that you extract data from std::istringstream much the same way you do with std::cin. The main difference is that you read the input from a string instead.
@jlb: you seem to know a lot about stringstreams, maybe you could have helped OP in the first place rather than giving him/her the run around, specially as the OP had demonstrated personal efforts
I don't want anyone to do the thinking for me. I just haven't found any documentation that is simple enough for me to understand, that's why I ask to get it explained as if i were 5. And @gunnerfunner gave me a good explanation, so thank you for that!