On Oct 1, 12:12 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Michael Angelo Ravera wrote:
Is there a reasonable way (apart from parsing the line myself which I
can do, but would like to avoid) to have an extract fron cin return a
null string when a (second) line ender is entered, but also to ignore
other whitespace characters before starting the extract?
Are you aware of 'getline' function? How about 'ignore' member of
'istream' (or whichever it is, actually)?
The situation I have is that I would like to present a default value
and have the user accept it by simply pressing the retrun key, but to
enter the proper value, if the default is unacceptable.
If you use getline, you don't have to parse anything yourself, you
could still form 'istringstream' from the string and extract from it
just like you would from your input stream.
I am very aware of getline. This basically amounts to parsing the line
myself. What I want to do here is to have the previous extract
operation remove any trailing whitespace and one set of line enders,
if any, but to have the current operation return a null string on
encountering line ender, but to ignore any leading whitespace. I can
certainly code it this way, but there should be any easier way and I
suspect that there is.