Jump to content
  • Advertisement
Sign in to follow this  
dhanyu

READ/WRITE to a file GLDouble

This topic is 4884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!