473,326 Members | 1,972 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,326 software developers and data experts.

std::ios_base::width usage problem

Lu
To teach myself about std::ios_base::width, I make the following program:

[jxlu@edusrv jxlu]$ cat pi.cpp
// modify precision
#include <iostream>
using namespace std;

int
main ()
{
double f = 3.14159265357989;
cout.width (10);
cout.precision (4);
cout << f * 0.01 << ' ' << f * 0.1 << ' ' << f << ' ' << f *
1000000 << endl;
cout.precision (5);
cout << f * 0.01 << ' ' << f * 0.1 << ' ' << f << ' ' << f *
1000000 << endl;
return 0;
}
[jxlu@edusrv jxlu]$ g++ -Wall -o pi pi.cpp
[jxlu@edusrv jxlu]$ ./pi
0.03142 0.3142 3.142 3.142e+06
0.031416 0.31416 3.1416 3.1416e+06
[jxlu@edusrv jxlu]$

But what I want is:
0.03142 0.3142 3.142 3.142e+06
0.031416 0.31416 3.14163.1416e+06

How can I make it?

Sincerely,
Lu
Jul 19 '05 #1
0 1780

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

Similar topics

11
by: John | last post by:
Hello all, I am trying to read in lines into a buffer from a file. Normally I would do this very low-level, but I have come to the conclusion I must stop doing everything the hard way. So, I...
1
by: Antti Granqvist | last post by:
Hello! I have following object relations: Competition 1--* Category 1--* Course 1 | | * Course
14
by: Mike - EMAIL IGNORED | last post by:
Using RH9, from this fragment: fstream theStream_; string fPath = "myFile"; int mode = O_EXCL | O_CREAT; theStream_.open(fPath.c_str(),mode); I get the failure shown below. ...
0
by: Martin Magnusson | last post by:
I have defined a number of custom stream buffers with corresponding in and out streams for IO operations in my program, such as IO::output, IO::warning and IO::debug. Now, the debug stream should...
6
by: Geoffrey S. Knauth | last post by:
It's been a while since I programmed in C++, and the language sure has changed. Usually I can figure out why something no longer compiles, but this time I'm stumped. A friend has a problem he...
4
by: luke.yolanda | last post by:
I write a simple problem ,as: ****************************** //temp.cpp #include<iostream.h> int main(void){ cout<<"123131231"; return 0; }
7
by: DaVinci | last post by:
//error happen even when there existe a a.txt file #include<fstream> #include <string> #include <iostream> using std::string; using std::fstream; int main() { string s = "a.txt"; fstream...
6
by: s_4 | last post by:
Hello! Sorry about my english - I write to you from poland. I have strange problem. Bind() return '16'. Documentation say that it should return 0 (no error) or -1 (some error). Here is the code...
1
by: Ron Eggler | last post by:
Hi, I'm developing software for Linux on my desktop. The software gets compiled and the binary is downloaded to the target system where i can't install a debugging system or something. I've...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.