setting field width for formating

Im trying to print 3 fields equally separated on the cout stream. i tried putting a tab between each field but because they are all different lengths i lose formating. im trying to print like a grid.

i tried setw(10). this worked similar to '/t' and the output was staggered. also im trying to do it via friend output << operator.

each class defines << operator

so i can do something like
1
2
cout << firstline << endl; // prints field1    field2    field3
cout << secondline << endl;// prints field1    field2    field3 
Last edited on
Why can't you use setw() with the friend operator?
C++ IO manipulators to me is too verbose and not intuitive. I still like my printf, scanf format specifier format.

%d
%s
%10s
%c
%f
....

Above is so clear! :P
Topic archived. No new replies allowed.