The field width determines the minimum number of characters to be written in some output representations. If the standard width of the representation is shorter than the field width, the representation is padded with fill characters at a point determined by the format flag adjustfield (one of left, right or internal).
The fill character can be retrieved or changed by calling the member function fill.
The format flag adjustfield can be modified by calling the member functions flags or setf, by inserting one of the following manipulators: left, right and internal, or by inserting the parameterized manipulator setiosflags.
DeclarationFollowing is the declaration for ios_base::width function.
get (1) streamsize width() const; set (2) streamsize width (streamsize wide);Parameters
wide − New value for the stream's field width.
Return ValueThe value of the field width before the call.
ExceptionsBasic guarantee − if an exception is thrown, the stream is in a valid state.
Data racesAccesses (1) or modifies (2) the stream object. Concurrent access to the same stream object may cause data races.
ExampleIn below example explains about ios_base::width function.
#include <iostream> int main () { std::cout << 100 << '\n'; std::cout.width(10); std::cout << 100 << '\n'; std::cout.fill('x'); std::cout.width(15); std::cout << std::left << 100 << '\n'; return 0; }
Let us compile and run the above program, this will produce the following result −
100 100 100xxxxxxxxxxxx
ios.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4