I wrote a program that creates a text file with some letters using ofstream.
Now I would like to format the text so that the letters are written in groups
of 5 and the rows are all the same length( i.e. DANIWEBFORUM becomes DANIW
EBFOR UM). To do this the fprintf function seemed the most appropriate. in the
following example I use integers, but it is just an example.
Your method will work. But you cannot format the output the way you want it
with the fprintf.
You are reading one character at a time. Print 5 characters then print a
space.
To force a line feed print the linefeed character "\n".
Your format string should be just an "i". What you have now, "%-5.5i", will
print a single number of 5 digits and 5 decimal places.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I wrote a program that creates a text file with some letters using ofstream.
Now I would like to format the text so that the letters are written in groups
of 5 and the rows are all the same length( i.e. DANIWEBFORUM becomes DANIW
EBFOR UM). To do this the fprintf function seemed the most appropriate. in the
following example I use integers, but it is just an example.
can this method work? or there is some function that I can use directly when
creating the file with ofstream?
please help
Your method will work. But you cannot format the output the way you want it
with the fprintf.
You are reading one character at a time. Print 5 characters then print a
space.
To force a line feed print the linefeed character "\n".
Your format string should be just an "i". What you have now, "%-5.5i", will
print a single number of 5 digits and 5 decimal places.