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 ;

Recommended Answers

All 4 Replies

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.

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.

Welcome to the tedium that can be found in C++. This particular feeling is particularly prevalent with formatted output.

ok, so does anyone how I can fix this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.