DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Another question (http://www.daniweb.com/forums/thread158958.html)

imput1234 Nov 22nd, 2008 1:17 pm
Another question
 
How do I set a fixed number of places.

for example

I want 1 to be 01.

this is what I've been trying, but never works for some reason. Does anyone know how to do this. Thanks.

int i = 1;
cout << setprecision(2) << 1 ;

Lerner Nov 22nd, 2008 1:22 pm
Re: Another question
 
I'd try using strings or develop an internal representation using ints, but a display format that is right justified and filled to left to a specified field size using zeros by using ostream manipulators.

imput1234 Nov 22nd, 2008 1:23 pm
Re: Another question
 
that was just an example, the program actually displays 100's of numbers.
the only manipulator I can think of is setw

but I dont want to repeat it several times.

Lerner Nov 22nd, 2008 4:35 pm
Re: Another question
 
Welcome to the tedium that can be found in C++. This particular feeling is particularly prevalent with formatted output.

imput1234 Nov 23rd, 2008 12:21 am
Re: Another question
 
ok, so does anyone how I can fix this?


All times are GMT -4. The time now is 12:30 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC