ios::width vs.< iomanip> setw()

Jan 29, 2012 at 7:21pm
I wanted to know if when formatting output if there is a preference between iso::width from the <iostream> header and setw() in the <iomanip> header? If there is a preference or reason to use one over the other please explain why.

Thanks in advance,
pxm76
Jan 29, 2012 at 9:08pm
If multiple output values are to be formatted, each with its own width, using the manipulator makes the code more readable.

cout << setw(25) << name << setw(12) << phone << setw(4) << age << '\n' ;

Jan 29, 2012 at 9:11pm
That makes sense. Thanks for the reply!
Topic archived. No new replies allowed.