Henry Poon's Blog

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.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Next Post

Previous Post

Leave a Reply

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

© 2024 Henry Poon's Blog

Theme by Anders Norén