The getline function has a character version that is a member function, as well as a global version that takes strings. Why aren't they both member functions? The current way makes it seems as though there isn't a string version.
istream& istream::getline(char* s, streamsize n) is part of the stream interface.
istream& getline(istream& is, string& str) is an extension method from the string library (just like the istream &operator>>(istream&, string&)).
This design was probably chosen in order to decouple iostreams from string, as fstream::open() also does not take std::string arguments but rather const char*.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With