By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

setting and resetting stream precision

P: n/a
Hi, I would like to save a stream's output precision and then change the
precision and then restore it. One example I found was using
ios_base::fixed, and ios_base::floatfield. But on my machine this only
gives 6 or 8 digits after the decimal. I would like at least 12. If I do
cout.precision(12), then cout is forever set to 12 precisions from that
point on. I guess I can call cout.precision(4) when I'm done, but how do I
know that 4 is the default?

example:
ios_base::fmtflags f = cout.flags();
cout.setf(ios_base::fixed, ios_base::floatfield);
cout << 12.5123123123123123123123123123 << endl;
cout.flags(f);
cout << 12.5123123123123123123123123123 << endl;

Thanks in advance.
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Tue, 5 Aug 2003 11:33:14 -0400, "john smith" <as**@asdf123asdf.net>
wrote:
Hi, I would like to save a stream's output precision and then change the
precision and then restore it. One example I found was using
ios_base::fixed, and ios_base::floatfield. But on my machine this only
gives 6 or 8 digits after the decimal. I would like at least 12. If I do
cout.precision(12), then cout is forever set to 12 precisions from that
point on. I guess I can call cout.precision(4) when I'm done, but how do I
know that 4 is the default?

example:
ios_base::fmtflags f = cout.flags();
cout.setf(ios_base::fixed, ios_base::floatfield);
cout << 12.5123123123123123123123123123 << endl;
cout.flags(f);
cout << 12.5123123123123123123123123123 << endl;


http://www.boost.org/libs/io/doc/ios_state.html

Tom
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.