Ouput to text file as a paragraph instead of vertical and horizontal line?

I'm writing a program that get integers from a text file and ouputs it to another but when i ouput it, the integers are in vertical form:
78796
117894
109974
98204
101252
114826
32120
49940
32112
102058
How do i get it to be like this:
82848 101120 97206 115690 111120 110904
32644 78796 117894 109974 98204 101252
114826 32120 49940 32112 102058 111850
After 5 intgers it just to a new line.
1
2
3
4
5
6
7
8
9
10
while( input >> x )
{
if(EvenTest(x))

{
output << x << endl; // it outputs vertically but without the endl its horizontal.

}

}
Last edited on
You will want to count how many times you output a number and print and endl every 5 times.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
int i = 0;
while ( input >> x)
{
    if (EvenTest(x))
    {
          output << x;
          if (i >= 5)
          {
              output << endl;
              i = 0;
          }
          i++; 
    }
}



Or you could use a for loop which might look prettier.
Last edited on
Topic archived. No new replies allowed.