When you use SETW (n) to set the output width, the default value is right alignment, as shown below:
// Include <iostream> // include <iomanip> STD: cout <STD: SETW (5) <"1" <STD: Endl; STD :: cout <STD: SETW (5) <"10" <STD: Endl; STD: cout <STD: SETW (5) <"100" <STD: Endl; STD: cout <STD: SETW (5) <"1000" <STD: Endl; //// output result: //// 1 // 10 // 100 // 1000 //
To align it left, insert STD: Left as follows:
// Include <iostream> // include <iomanip> STD: cout <STD: Left <STD: SETW (5) <"1" <STD:: Endl; STD: cout <STD: Left <STD: SETW (5) <"10" <STD: Endl; STD :: cout <STD: Left <STD: SETW (5) <"100" <STD: Endl; STD: cout <STD :: left <STD: SETW (5) <"1000" <STD: Endl; // output result: /// 1 // 10 // 100 // 1000 //
Similarly, you only need to insert STD: right to the right alignment, but the right alignment is the default state and does not need to be explicitly declared.