Working around the Standard Library

We can't use the >> operator because the implementation of that operator in the C++ standard library stops reading data into a string variable whenever it sees a blank or other “white space” character, rather than only at the end of a line. Therefore, if we tried to use >> to read a line of data such as “3-ounce cups” into m_Name, we would only get the part of it before the first blank. The rest of the data would be left on the input stream for the next read operation to retrieve.

Personally, I think it would be much better for >> to read the whole line into a string and as we'll see, that's how I did it when I implemented my own string class. But, as Bjarne has said, “Victories over the type system of a language ...

Get C++: A Dialog Programming with the C++ Standard Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.