More Improved Extractors and Inserters Insertion and extraction still do not fit seamlessly into the iostream framework. The inserters and extractors for built-in types can be controlled through formatting flags that our operators thus far ignore. Our operators don't observe a field width while inserting, or skip whitespaces while extracting, and so on. They don't care about error indication either. We should certainly set some state bits in the respective stream's state and throw or rethrow exceptions, if the exception mask says so.
Some recommendations follow.
In its constructor and destructor, the sentry performs certain standard tasks, like skipping white characters, flushing tied streams, etc. See the Class Reference for a detailed explanation. Reset the width after each usage. Set failbit if the formatting or parsing itself fails. Set eofbit when the end of the input sequence is reached.