Gregor Razdrtic said:
Oh .... yes ... i wrote incorrect, let me fix this.
First of all, plese don't top-post.
float to std::string
One solution follows
float fVar = 120.5;
char* tmpChar = new char[sizeof(float)+1];
'sizeof(float)' does not give you "how many bytes are needed for the
decimal representation of a float". Change your fVar to 120000.5 and
you will have undefined behaviour on your hands.
You have to use (fabs(log10(fVar)) + 8) (or something like that) to
determine how many chars to allocate.
sprintf(tmpChar, "%f", fVar);
std::string svar = tmpChar;
delete [] tmpChar;
Maybe not best , but working well
No, not working well. You allocate 5 chars, but print out 6 (five
to represent the '120.5' and the sixth is the terminating 0. You
simply write too much into 'tmpChar' than it has room.
V