help with formatting output

M

mark

for(int k=0;k<50;++k)
{if(k==10 || k==20 || k== 30 || k==40)
cout<<endl;}
else
cout<<" "<<k<<" ";
}
this prints as follows

1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17....


ie the numbers are not left or right aligned or appear in neatly
arranged columns.

How to get the numbers printed so that they appear (like left aligned)
in neatly arranged columns like below

1 2 3 4....
11 12 13 14...
21 22 23 24...
 
V

Victor Bazarov

mark said:
for(int k=0;k<50;++k)
{if(k==10 || k==20 || k== 30 || k==40)
cout<<endl;}
else
cout<<" "<<k<<" ";
}
this prints as follows

1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17....


ie the numbers are not left or right aligned or appear in neatly
arranged columns.

How to get the numbers printed so that they appear (like left aligned)
in neatly arranged columns like below

1 2 3 4....
11 12 13 14...
21 22 23 24...

Please read about 'setw' and other stream manipulators.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top