\0 character in istream::getline()

1.9k views Asked by At

What happens if a file contains a \0 character when using istream::getline()? Will be it be omitted or still assigned into a field in the string buffer?

2

There are 2 answers

0
Rahul Tripathi On

From std::istream::getline

A null character ('\0') is automatically appended to the written sequence if n is greater than zero, even if an empty string is extracted.

0
Bo M. Petersen On

Assuming you meant istream::getline() I don't see why a null char would ignored. Reading the description on http://en.cppreference.com/w/cpp/io/basic_istream/getline I see nothing that treats \0 in any special way unless you use it as the delimiter.

Short story: it get placed in the extracted string.