I am learning c++. I don't understand how to write a long double value in a file. I don't know the number of decimals values, so i think i can't use setprecision. Can you show me hints?
Because this subject is for me a way to understand basic c++, i should only use
iostream
and fstream
.
I don't understand why ofstream decide to truncate my number
long double number=0.12345678987654321012345678987654321012 ..etc;
ofstream myfile("name.txt", ios::binary);
myfile << number ;
It write only 0.1234
Things i tried so far:
myfile << number ;
and
char *conversion = reinterpret_cast<char *>(&number );
myfile << *(reinterpret_cast<double *>(conversion));
myfile .close();
and
myfile.write((char *)&resultat, sizeof(long double)) ;