setting and resetting stream precision

J

john smith

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.
 
T

tom_usenet

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top