Why are there two getlines, one for char* and one for std::string? Why is getline a seperate function for std::strings and a part of an istream for char*?
Why are there two getlines, one for char* and one for std::string? Why is getline a seperate function for std::strings and a part of an istream for char*?
String isn't guaranteed to be a type. It is only defined if the string header was included. Hence, if the istream header was included (and the string header wasn't), there would be an undefined error. However, if there was an #ifdef, it wouldn't work if string was included after istream. The only solution would be to #define to string symbol before the headers. I guess the standards committee feel it is more elegant to use a global function instead (and eliminate the possible #define conflict).
Further, istream is old. It was originally a class (now it's a typedef for a templated class), and istream existed (with virtually the same interface) since the oldest days of C++. Long before there was a std::string (or even a std namespace, or even namespaces at all).
Yeah, but why would they be afraid to update a header file?