C++ Manipulator setwC++ manipulator setw function stands for set width. This manipulator is used to specify the minimum number of character positions on the output field a variable will consume. This manipulator is declared in header file <iomanip>. SyntaxParametern: number of characters to be used as filed width. Return valueThis function returns an object of unspecified type. The setw function should only be used as a stream manipulator. Data RacesThe stream object on which it is inserted or extracted is modified and concurrent access to the same stream object may introduce data races. ExceptionsObject is in a valid state, if any exception is thrown. Example 1Let's see the simple example to demonstrate the use of setw: Output: 24 Example 2Let's see another simple example: Output: no setw:42 setw(6): 42 setw(6), several elements: 89 1234 Input from "hello, world" with setw(6) gave "hello" Example 3Let's see another simple example: Output: 200 300 200 300 200 300 200 300
Next TopicC++ Manipulator
|