how can I peek the next non-whitespace character from a std::istream? My
ugly solution is this:
char c;
stream >> c;
stream.unget();
--
Daniel
Try
stream >> skipws;
int ch = stream.peek();
--
With best wishes,
Igor Tandetnik
"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage
Make it
stream >> ws;
> "Igor Tandetnik" <itand...@mvps.org> wrote in message
>
> stream >> ws;
> int ch = stream.peek();
Thanks!
--
Daniel
> "Igor Tandetnik" <itand...@mvps.org> wrote in message
>
> stream >> ws;
> int ch = stream.peek();
Why do I have to re-set the stream to skip whitespace? I would like to be
able to do it once. Surely there must be simple way to permanently set a
stream to skip whitespace?
--
Daniel
There is - see skipws and noskipws. However, this flag only works for
formatted input - basically, when you use operator>>. Unformatted input
methods (such as read() and peek() ) always reads raw elements with no
preprocessing.