0

i have a very basic c++ problem.

this is my problem
first i am assigning an integer.

int i=000;

when i am writing the value of this integer into a file its writing only one "0".

How can i write the all four zero in the file.

actually i have to increment the value of "i=000" to 999.

The desired out put to the file is


000
001
002
003
...
...
...
999

bt iam getting the out put like this


0
1
2
.
.
.
999


please help.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Fbody
0

Have you tried to look at the patterns in printf like "%4d" "%-4d" "%04d" etc follwed by an integer value in printf ? These patterns are used to generate specific formatting of left allignment,right allignment,fixing the width of the input and also filling the empty spaces with the values you want. These are given in detail in K & R. Try them I am sure you can figure out the rest yourself as you don't exactly need anything other than this basic information to solve your present problem. :)

Edited by csurfer: n/a

0

Im doing this with c++.And i want to write these into a file.How Can i do this.

0

The output function printf() is valid C++, it's just a function that's inherited from C.

If you in fact want to do this in purely C++, you'll have to use manipulators.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.