473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Equivalent of fprintf's -20.15g formatting with C++ formatted streams ?

Hi,
could anyone please tell me how I can get the equivalent of this:
fprintf(aFile,"-20.15g",aDouble);
but in C++ using formatted streams?
I tried with C++ formatted streams using:
aStream.width(20);
aStream.precision(15);
but then if there's a very small value, scientific notation is not used
automatically and precision is lost (like in 0.000000000000003 instead
of 3.33333333333e-15).
I must be missing something here...
Koen
Jul 22 '05 #1
1 2440
Koen wrote:
could anyone please tell me how I can get the equivalent of this:
fprintf(aFile,"-20.15g",aDouble);
but in C++ using formatted streams?
I tried with C++ formatted streams using:
aStream.width(20);
aStream.precision(15);
but then if there's a very small value, scientific notation is not used
automatically and precision is lost (like in 0.000000000000003 instead
of 3.33333333333e-15).
I must be missing something here...


What book are you reading? All the manipulators are there for you to
use. See 'scientific' or 'fixed', see 'left' and 'right'... IOW RTFM

V
Jul 22 '05 #2

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

Similar topics

20
by: Mark | last post by:
I am using gnu g++ version 3.3.2, trying a simple test to read in and then write out a large (100,000 line) text file ########################################## CSTDIO VERSION TO READ/WRITE...
11
by: Steven T. Hatton | last post by:
OK, I take back the nasty stuff I said about printf. At least until I see a similarly concise way of writing this using C++ formatters. I want to convert the following to something I can put onto...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
7
by: Kayle | last post by:
For preservation of indentation when moving the C source file from Windows to Linux machine, what is the advice to format the code. Should the code formatted using spaces instead of tabs? When...
6
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being...
6
by: Magix | last post by:
Hi, I want to use fprintf to write to a file. My question about the formatted output How can I format so that I can allocate certain width for each %s (Left-aignlied) ? Example: fprintf("%s...
4
by: GGarramuno | last post by:
I have a program that expects its input in a specific format. Mainly, it expects floating-point values to be formatted in the form: 1.32 1. 3. 3.2345 In case you missed it, all floating...
11
by: Dustan | last post by:
Is there any builtin function or module with a function similar to my made-up, not-written deformat function as follows? I can't imagine it would be too easy to write, but possible... 'I am...
11
by: David Mathog | last post by:
In the beginning (Kernighan & Ritchie 1978) there was fprintf, and unix write, but no fwrite. That is, no portable C method for writing binary data, only system calls which were OS specific. At...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.