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.

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. :)

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

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.

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.