How can i convert a double into a char i can put into an array of chars?
thnx
How can i convert a double into a char i can put into an array of chars?
thnx
Time for TOTAL WAR
sprintf() or one of the stream members, eg...
Code:float X; char Buffer[10]; X = 5.7; sprintf(Buffer, "%f", X);
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
How would you solve it using one of the stream members ?
lol thats actually very clever, sprintf prints the double into a string (buffer) so that it goes in looking just like it would if you cout<<'d it. At least thats how I understand it.
Compile the code and see for yourself.
>>> How would you solve it using one of the stream members ?
Like that...
Code:#include <strstream> #include <iostream> using namespace std; int main() { float X; char Buffer[10]; ostrstream OutStr(Buffer, sizeof(Buffer)); X = 5.7; OutStr << X << ends; cout << Buffer << endl; return 0; }
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.