473,805 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting and resetting stream precision

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::float field. 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::fmtfl ags f = cout.flags();
cout.setf(ios_b ase::fixed, ios_base::float field);
cout << 12.512312312312 312312312312312 3 << endl;
cout.flags(f);
cout << 12.512312312312 312312312312312 3 << endl;

Thanks in advance.
Jul 19 '05 #1
1 5389
On Tue, 5 Aug 2003 11:33:14 -0400, "john smith" <as**@asdf123as df.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::fixe d, and ios_base::float field. 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::fmtf lags f = cout.flags();
cout.setf(ios_ base::fixed, ios_base::float field);
cout << 12.512312312312 312312312312312 3 << endl;
cout.flags(f );
cout << 12.512312312312 312312312312312 3 << endl;


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

Tom
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1577
by: Thomas Chassaing | last post by:
Hi, I just installed the mxNumber package and looking trough the documentation I found no means to set the default precision for Float numbers (I think it is set to 64bits). Does anyone know how the default precision can be changed, or do I have to use the Float(value,precision) constructor all the time? Thanks T. Chassaing
3
2673
by: John Flynn | last post by:
hi, having problems reading from and writing back to the same file. basically, i want to read lines of text from a file and reverse them and write them back to the same file.. it has to replace the text its reversing eg.
3
2421
by: jjleto | last post by:
I want to reset an ostringstream so that: ostringstream oss; oss << "foo "; cout << oss.str(); // what should go here ? oss << "bar"; cout << oss.str(); issues
5
2180
by: Riku Jarvinen | last post by:
Hi everyone, I asked another question regarding this same subject about a week ago. See thread: http://groups.google.fi/group/comp.lang.c++/browse_frm/thread/cc57b579d6832732/530bae667a479add#530bae667a479add So, the basic idea is to have a compact logger class which can be used like the std::cout stream and add extra functionality to it (line numbering, some output counters etc.).
1
3879
by: simon | last post by:
I have an unbound RTF2 control in an Access 2003 form which I set to show either unformatted text or else text with words and sentences highlighted. I do this by setting the PlainText property, getting back the rtfText and then adding the highlighting strings and resetting rtfText as below: sqry = "Select * from TextContent where FileID = " & ID Set rs = CurrentDb().OpenRecordset(sqry, dbOpenSnapshot) With rtfUnformatted ..rtfText = ""
4
4086
by: Ian Davies | last post by:
Hello I am struggling for a solution to clear some fields on my webpage that takes their values from some sessions My solution below works when the button is clicked twice. I sort of know why I have to click it twice to do the job (the first submit resets the sessions but this it too late to change the field values, which requires another submit to pick up the new session values). Problem is I cant think how to accomplish the resetting of...
0
1123
by: John Friedland | last post by:
'printf' allows an integer to be printed with a precision. "printf("|%5.2d|", 1)", for example, produces "| 01|". This doesn't seem to be possible with stream I/O - 'precision' only seems to be relevant to floating-point numbers. Can anyone tell me if I can do the above with stream I/O? I've attached a simple test program; the output is | 01|
4
1543
by: Bob | last post by:
I'm just starting PHP and MySQL - and really like the book by Welling and Thomsom. I've installed MySQL on my WinXP desktop, along with Apache and PHP. I have not figured out how to set a password for the root account. I've been able to set up a user account for myself, with a password, but not the root account. I understand this is not ideal. I've tried setting the password in My.ini but it doesn't seem to work. I must be doing...
1
6513
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.