cout.setf() How to print in center

I am using this code for printing into the center. But output is left justified.
please tell me what is the mistake and kindly correct this syntax.

cout.setf(ios::left|ios::right,ios::adjustfield);
cout<<setw(20)<<"Welcome";

Regards
There is no 'ios::center' justification. You have to do that yourself.

[edit]
Hint:
Length of "Welcome" = 7.
Length of field = 20.
Leading whitespace = (20 - 7) / 2 = 6.
Trailing whitespace = Length of field - Leading whitespace - Length of "Welcome" = 20 - 6 - 7 = 7.
Last edited on
Topic archived. No new replies allowed.