READ/WRITE to a file GLDouble

Started by
1 comment, last by dhanyu 18 years, 9 months ago
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
dhanyu
Advertisement
In ascii (expect some loss of precision unless you set the format flags appropriately):
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
thx enigma.. u are cool.............

I never expected fast reply

dhanyu

This topic is closed to new replies.

Advertisement