One thing I’m not pretty sure after googling for a while, is the returned string of getline(). Hope to get it confirmed here.
std::getline
This global version returns a std::string so it’s not necessarily null-terminated. Some compilers may append a ‘\0’ while the others won’t.
std::istream::getline
This function returns a c-style string so it’s guaranteed that the string is null-terminated.
Is that right?
Null termination is a concept that is applicable only to C strings; it does not apply to objects of
std::string– they let you find the size by callingsize(), and do not require null termination. However, strings returned fromstd::string‘sc_str()function are null terminated, regardless of where the data for the string came from.C++11 standard describes the prerequisites of the
operator [pos]in the section 21.4.5.2:Note the
pos < size(), as opposed topos <= size(): the standard explicitly allowsstd::stringobjects not to have null termination.