O'Reilly logo

Beginning C++ Programming by Richard Grimes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading numbers from strings using streams

The cin object, an instance of the istream class (in the <istream> library), can input characters from the console and convert them to the numeric form you specify. The ifstream class (in the <ifstream> library) will also allow you to input characters from a file and convert them to numeric form. As with outputting streams, you can use the stream classes with a string buffer so that you can convert from a string object to a numeric value.

The basic_istringstream class (in the <sstream> library) is derived from the basic_istream class, so you can create stream objects and extract items (numbers and strings) from these objects. The class provides this stream interface on a string object (the typedef ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required