|
-
December 3rd, 2010, 04:20 PM
#1
ifstream / ofstream precision
Hello,
I'd like to ask two different questions on a related topic please...
1. When I am writing float data to a text file, I want to set the precision. I know that with std::cout, you can write "std::cout.precision(5)" to set the precision to 5 decimal places. But writing "std: fstream.precision(5)" does not work. How can I do this?
2. When I read the file back again, I want to add a load of zeros to each float, after the 5 decimal places. For example, if my data file has the value "1.23456", which has been limited by setting the ofstream precision to 5 decimal places, I want to read in this value again, such that the float variable becomes "1.234560000000.....". When I have tried just reading it in normally using std::ifstream, it in fact sets my flat variable to the value "1.234599999999999....". This may seem a trivial difference, but it is actually crucial for my program.
Thanks for any help!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|