Functions That Convert strings to Floating-Point Types

The functions that convert strings to floating-point types each receive two parameters:

• A string containing the characters to convert.

• A pointer to a size_t variable where the function stores the index of the first character that was not converted. The default argument is a null pointer, in which case the function does not store the index.

Consider an example of converting a string to an floating-point value. Assuming the string:

string s( "123.45hello" );

the following statement converts the beginning of the string to the double value 123.45 and stores that value in convertedDouble:

double convertedDouble = stod( s );

Again, the second argument is a null pointer by default.

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.