N numbers per line (text file)
Oct 17, 2013 at 4:21am UTC
I need to know how to print numbers from a text file(that include numbers) 10 numbers per line
instead of a output like this:
100
90
80
78
67
56
20
78
99
54
89
100
90
80
I want to have 10 numbers per line like this :
100 90 80 78 67 56 20 78 99 54
89 100 90 80
Can someone please help me do this (from a text file)
What should I put between this
1 2 3 4 5
while ( !fin.eof())
{
}
Oct 17, 2013 at 6:10am UTC
Something like this may work well.
1 2 3 4 5 6 7
int count = 0, num;
while ( fin >> num )
{
cout << num << ' ' ;
if ( ++count%10 == 0 )
cout << endl;// print a newline each time count becomes a multiple of 10
}
Oct 18, 2013 at 8:24pm UTC
thankyou
Topic archived. No new replies allowed.