Can anyone help me copy the value of a string variable into a float variable using c++? The value of the string IS a number, but it needed to be input as a string, and then I need to transfer it into a float variable (or int, whichever works best). PLEASE HELP ME!!! This is not for a project or anything for school, it is for a private project of mine that will be featured on my website, www.manlawonline.org ok people? so please help me!!!! remember C/C++!!! Thank you in advance!
Copy value of a string variable into a float variable in C++?
double a;
char *val="3.1415926";
a=atof(val);
======================
Well, the answer above is for C only with char * as the string
C++ would be:
I hard coded 20 and 19...you can optimize those.
char val[20];
double a;
memset(val, '\0',20 );
string str = "3.1415926";
str.copy( val, 19 );
a=atof(val);
elephant ear
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment