O'Reilly logo

C++11 for Programmers, Second Edition by Harvey M. Deitel, Abbey Deitel, Paul J. Deitel

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

Functions That Convert strings to Integral Types

Consider an example of converting a string to an integral value. Assuming the string:

string s( "100hello" );

the following statement converts the beginning of the string to the int value 100 and stores that value in convertedInt:

int convertedInt = stoi( s );

Each function that converts a string to an integral type actually receives three parameters—the last two have default arguments. The parameters are:

• A string containing the characters to convert.

• A pointer to a size_t variable. The function uses this pointer to store 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.

• An int from 2 ...

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