hex | manipulator function |
ios_base& hex ( ios_base& str ); |
<ios> |
Use hexadecimal base
Sets the basefield format flag for the str stream to hex.
When basefield is set to hex, integral numerical values inserted into the stream are expressed in the hexadecimal base (radix 16). For input streams, extracted values are also expected to be expressed in the hexadecimal 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 integral values using decimal base format. |
hex | read/write integral values using hexadecimal base format. |
oct | read/write integral values using octal base format. |
The basefield flag is set to dec in standard streams on initialization.
Notice that the basefield flag only affects the insertion/extraction of integer values. Floating-point values are always treated in the decimal base.
Notice also that no base prefix is implicitly prepended to the number unless the showbase format flag is set.
Parameters
- str
- Stream object where to apply.
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
A reference to the stream object.Example
// modify basefield #include <iostream> using namespace std; int main () { int n; n=70; cout << hex << n << endl; cout << dec << n << endl; cout << oct << n << endl; return 0; } |
The execution of this example displays something similar to:
46 |
See also
dec | Use decimal base (manipulator function) |
oct | Use octal base (manipulator function) |
ios_base::flags | Get/set format flags (public member function) |
ios_base::setf | Set specific format flags (public member function) |