Henry Poon's Blog

C++ String to Double or Integer Conversion

[code]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[/code]

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.

© 2022 Henry Poon's Blog

Theme by Anders Norén

%d bloggers like this: