function
<ios> <iostream> <iostream>
std::dec
ios_base& dec (ios_base& str);
Use decimal base
Sets the basefield format flag for the str stream to dec.
When basefield is set to dec, integer values inserted into the stream are expressed in decimal base (i.e., radix 10). For input streams, extracted values are also expected to be expressed in decimal base when this flag is set.
The basefield format flag can take any of the following values (each with its own manipulator):
flag value | effect when set |
dec | read/write integer values using decimal base format. |
hex | read/write integer values using hexadecimal base format. |
oct | read/write integer values using octal base format. |
For standard streams, the basefield flag is set to dec on initialization.
Parameters
- str
- Stream object whose basefield format flag is affected.
Because this function is a manipulator, it is designed to be used alone with no arguments in conjunction with the insertion (<<
) and extraction (>>
) operations on streams (see example below).
Return Value
Argument str.
Example
1 2 3 4 5 6 7 8 9 10
|
// modify basefield
#include <iostream> // std::cout, std::dec, std::hex, std::oct
int main () {
int n = 70;
std::cout << std::dec << n << '\n';
std::cout << std::hex << n << '\n';
std::cout << std::oct << n << '\n';
return 0;
}
| |
Output:
Data races
Modifies str. Concurrent access to the same stream object may cause data races.
Exception safety
Basic guarantee: if an exception is thrown, str is in a valid state.
See also
- hex
- Use hexadecimal base (function
)
- oct
- Use octal base (function
)
- ios_base::flags
- Get/set format flags (public member function
)
- ios_base::setf
- Set specific format flags (public member function
)