READ/WRITE to a file GLDouble
Hi all,
Dose anybody knows how to write from GLDOUBLE variable to a text file and read it back to a GLDOUBLE variable. Since this is 64-bit value ... I doubt that c++ libraries could help.
thank you
In ascii (expect some loss of precision unless you set the format flags appropriately):
In binary (no loss of precision):
Enigma
GLdouble writeMyDouble = 3.14159265358979323846;GLdouble readMyDouble;{ std::ofstream writer("my_ascii_file.txt"); writer << writeMyDouble;}{ std::ifstream reader("my_ascii_file.txt"); reader >> readMyDouble;}std::cout << writeMyDouble << '\n' << readMyDouble << '\n';
In binary (no loss of precision):
GLdouble writeMyDouble = 3.14159265358979323846;GLdouble readMyDouble;{ std::ofstream writer("my_ascii_file.txt", std::ios::binary); writer.write(reinterpret_cast< char * >(&writeMyDouble), sizeof(writeMyDouble));}{ std::ifstream reader("my_ascii_file.txt"); reader.read(reinterpret_cast< char * >(&readMyDouble), sizeof(readMyDouble));}std::cout << writeMyDouble << '\n' << readMyDouble << '\n';
Enigma
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement