Provides capabilities for handling output formatting
The library provides features for handling output formatting, such as the base used when formatting integers and the precision of floating point values .
It has the following functions:
setiosflags - Defines flags format
resetiosflags - Resets flags format
setbase - Sets the base of the flags
setfill - Defines the filling of characters
setprecision - Sets the precision of decimals
setw - Sets the width of a field
get_money - Gets the monetary value
put_money - Insert the monetary value
get_time - Get the time and date
put_time - Get the time and date
Some examples
setfill and setw
Fill with a certain character on the left side of the number(int, float, double,…)
Filled with 6 blank spaces(10 minus the number of characters), so the output will be: 3.69. If we change std::setfill (' ') to std::setfill ('-') the output will be: ——3.69 .
setprecision
Defines how many digits you want to appear if there is no more after the comma ( in this case, point . ), it will fill with 0 zeros if we use std::fixed .
Output: 3.14
Output: 3.142 because the next significant number is equal to or greater than 5, so it approximates the previous one.
And if you change it to std::setprecision( 9 ), the output will be: 3.14159 will not complete with zeros, but using std::fixed
The output will be: 3.141590000
get_money and put_money
Informs the value in integer, in other words transforms: float, double,… in integer. They are useful for use with data entry. Example: