|
setbase
manipulator function
<iomanip>
smanip setbase ( int base );
Set basefield flag
Sets the basefield format flag to one of its possible values: hex, dec or oct depending on the value of the base parameter.
The basefield flag is used in certain input and output operations to determine the numeric base to be used to interpret numeric values.
This manipulator is declared in header <iomanip>, along with the other parameterized manipulators: resetiosflags, setiosflags, setfill, setprecision and setw. This header file declares the implementation-specific smanip type, plus any additional operator overload function needed to allow these manipulators to be inserted and extracted to/from streams with their parameters.
Parameters
- base
- Numerical radix to be used.
This value should be 8, 10 or 16.
Return Value
Unspecified. This function should only be used as a stream manipulator.
Example
1 2 3 4 5 6 7 8 9 10
|
// setbase example
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
cout << setbase (16);
cout << 100 << endl;
return 0;
}
|
This code uses the setbase manipulator to set hexadecimal as the basefield flag. The output of this example is the hexadecimal value of 100, i.e. 64.
See also
oct | Use octal base (manipulator function) |
dec | Use decimal base (manipulator function) |
hex | Use hexadecimal base (manipulator function) |
|