function
<ios> <iostream>
std::showbase
ios_base& showbase (ios_base& str);
Show numerical base prefixes
Sets the showbase format flag for the str stream.
When the showbase format flag is set, numerical integer values inserted into output streams are prefixed with the same prefixes used by C++ literal constants: 0x for hexadecimal values (see hex), 0 for octal values (see oct) and no prefix for decimal-base values (see dec).
This option can be unset with the noshowbase manipulator. When not set, all numerical values are inserted without base prefixes.
For standard streams, the showbase flag is not set on initialization.
Parameters
- str
- Stream object whose 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
|
// modify showbase flag
#include <iostream> // std::cout, std::showbase, std::noshowbase
int main () {
int n = 20;
std::cout << std::hex << std::showbase << n << '\n';
std::cout << std::hex << std::noshowbase << 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.