Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > setting and resetting stream precision

Reply
Thread Tools

setting and resetting stream precision

 
 
john smith
Guest
Posts: n/a
 
      08-05-2003
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.


 
Reply With Quote
 
 
 
 
tom_usenet
Guest
Posts: n/a
 
      08-05-2003
On Tue, 5 Aug 2003 11:33:14 -0400, "john smith" <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the different between byte stream and character stream? dolphin Java 6 03-18-2007 01:58 PM
setting precision with C++ big-red C++ 2 10-03-2006 10:00 PM
Specifying integer precision with Stream I/O John Friedland C++ 0 07-21-2006 10:10 PM
resetting setting on an efficent networkls router modem joe Computer Support 6 07-18-2005 01:49 PM
Setting the default precision in mxNumber Thomas Chassaing Python 1 06-04-2004 04:40 PM



Advertisments