How can I convert a double into a const char, and then convert it back into a double?
I'm wanting to convert the double to a string, to write it to a file via fputs, and then when I read the file, it will need to be converted back into a double.
I'm using Visual C++ 2010 Express Edition.
Since you added C++ to your tags, I suggest you use
std::stringstream
:You can use these functions to convert to and from:
Example:
Use this funcition :
If you just want to write the
double
values to file, you can simply write it, without converting them intoconst char*
. Converting them intoconst char*
is overkill.Just use
std::ofstream
as: