C++ String to Double or Integer Conversion

string str = "some number in the form of a string";

double a;

int b;

a = atof( str.c_str()); //conversion to double

b = atoi( str.c_str()); //conversion to int

If the string that is being converted is actually not a number, then it will return a zero.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.