Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » put32 for double precision values..
put32 for double precision values.. [message #35486] Wed, 22 February 2012 14:22 Go to next message
Monty.mvh is currently offline  Monty.mvh
Messages: 31
Registered: July 2011
Location: Bangalore
Member
Hi,

FileOut function put32 will write integer values into file..
Is there a way where i can put double precision values (say 3.142) directly into file..


Re: put32 for double precision values.. [message #35487 is a reply to message #35486] Wed, 22 February 2012 15:27 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Monty.mvh wrote on Wed, 22 February 2012 14:22

Hi,

FileOut function put32 will write integer values into file..
Is there a way where i can put double precision values (say 3.142) directly into file..


Hi Monty,

Yes and no Smile You could use ugly casting trick and and force the double to go through the Put32 function (or better Put64 - double is 64bit on most platforms!).

Much better in this case is to use Put():
double d = 3.142;
FileOut f;
// ...
f.Put(&d, sizeof(double));

That should do exactly what you want. To read it, you can use similarly:
FileIn f;
// ...
f.Get(&d,sizeof(double));


In fact, you can store almost any plain data type like this Wink

Best regards,
Honza
Re: put32 for double precision values.. [message #35537 is a reply to message #35487] Mon, 27 February 2012 13:54 Go to previous message
Monty.mvh is currently offline  Monty.mvh
Messages: 31
Registered: July 2011
Location: Bangalore
Member
Thank you Honza...It worked...Smile
Previous Topic: CoWork and shared memory
Next Topic: division by zero check
Goto Forum:
  


Current Time: Fri Apr 19 14:37:43 CEST 2024

Total time taken to generate the page: 0.05484 seconds