Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
filebuf
fstream
ifstream
ios
iostream
ios_base
istream
istringstream
ofstream
ostream
ostringstream
streambuf
stringbuf
stringstream
objects:
cerr
cin
clog
cout
types:
fpos
streamoff
streampos
streamsize
manipulators
boolalpha
dec
endl
ends
fixed
flush
hex
internal
left
noboolalpha
noshowbase
noshowpoint
noshowpos
noskipws
nounitbuf
nouppercase
oct
resetiosflags
right
scientific
setbase
setfill
setiosflags
setprecision
setw
showbase
showpoint
showpos
skipws
unitbuf
uppercase
ws


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