J
Juha Nieminen
I assume that using '\n' to print a newline is not portable because in
some systems newline consists actually of two characters and '\n' is
only one. Thus the only portable way of printing a newline character
(for example with std:
rintf) is "\n".
What does the standard say about '\n'? Can any assumptions be made
about it? Or is it a "never use it in portable code" value?
Of course this might present a problem when reading an input file in a
byte-by-byte fashion. If you want to detect a newline while reading it
like that, can you simply compare a read byte with '\n'? What if a
newline actually consists of more than one character?
The std::getline() function accepts a delimiter character as third
parameter (the input is read until this character appears). Since the
type of this parameter is char, doesn't this actually present a problem
if you want to give it a newline as delimiter? (I know that newline is
the default delimiter, but in theory it might be possible that you might
want to be able to specify it explicitly...)
If you repeatedly call std::getline(is, str, '\n') in a system where
newlines actually consist of more than one character, aren't the
additional characters read into the string (even though they really
shouldn't) instead of skipped? There doesn't seem to be a version of
std::getline() taking a string as delimiter parameter, so you can't give
it a "\n".
some systems newline consists actually of two characters and '\n' is
only one. Thus the only portable way of printing a newline character
(for example with std:
What does the standard say about '\n'? Can any assumptions be made
about it? Or is it a "never use it in portable code" value?
Of course this might present a problem when reading an input file in a
byte-by-byte fashion. If you want to detect a newline while reading it
like that, can you simply compare a read byte with '\n'? What if a
newline actually consists of more than one character?
The std::getline() function accepts a delimiter character as third
parameter (the input is read until this character appears). Since the
type of this parameter is char, doesn't this actually present a problem
if you want to give it a newline as delimiter? (I know that newline is
the default delimiter, but in theory it might be possible that you might
want to be able to specify it explicitly...)
If you repeatedly call std::getline(is, str, '\n') in a system where
newlines actually consist of more than one character, aren't the
additional characters read into the string (even though they really
shouldn't) instead of skipped? There doesn't seem to be a version of
std::getline() taking a string as delimiter parameter, so you can't give
it a "\n".