Topic: getline(s) and leading whitespace?
Author: "Mark Sebern" <msebern@nospam.sebern.com>
Date: 1998/02/02 Raw View
Maybe this has been asked and answered, but I couldn't find it in dejanews.
I'm puzzling over the two variants of getline (istream and string), and I
wonder if someone can tell me whether I have this right. I am working from
the 12/96 draft standard, so I may not be completely up to date.
The question has to do with whether the getline functions are supposed to
skip over any leading whitespace before collecting characters up to the
specified delimiter.
In 27.6.1.3 (unformatted input functions) the basic_istream variant of
getline says nothing about skipping whitespace before storing the first
charcter. I presume that any leading spaces (for example) would be stored
and that an "empty" input line (assuming the default newline delimiter)
would result in only the terminating NUL being stored. In other words, I
read the rule as "DON'T SKIP LEADING WHITESPACE".
In 21.3.7.9 (inserters and extractors) the string variant of getline
(simplified by dropping template details):
istream& getline (istream& is, string& str, char delim);
says "begins by constructing a sentry object k as if by
basic_istream<charT,traits>::sentry k(is) ...". I interpret this to mean
that if the skipws flag is set that whitespace characters will be discarded
before the first character is stored, since the sentry constructor would
consume the leading whitespace characters under this condition. In other
words, I read the rule here (with the stream default of skipws==true) as
"SKIP LEADING WHITESPACE".
Do I have this right? In other words, if I use the string variant of
getline and want to read "empty" lines or lines beginning with whitespace,
is it necessary to explicitly turn off the skipws flag for the duration of
the "getline" sequence? Am I correct that this "skipws==false" condition
should persist until it is explicitly reset?
Is there a reason why these two functions with the same name differ in this
way (if indeed they do)?
Thanks for your help.
-- Mark Sebern
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]