function
<iomanip>

std::setbase

/*unspecified*/ setbase (int base);
Set basefield flag
Sets the basefield to one of its possible values: dec, hex or oct, according to argument base.

Behaves as if setf(which,ios_base::basefield) were called on the stream on which it is inserted/extracted as a manipulator, with which being:
  • dec, if base is 10
  • hex, if base is 16
  • oct, if base is 8
  • zero, if base is any other value.

It can be inserted/extracted on input streams or output streams.

This manipulator is declared in header <iomanip>.

Parameters

base
Numerical radix to be used:
base argumentsame as inserting...
8oct
10dec
16hex
any otherresetiosflags(ios_base::basefield)

Return Value

Unspecified. This function should only be used as a stream manipulator (see example).

Example

1
2
3
4
5
6
7
8
9
// setbase example
#include <iostream>     // std::cout, std::endl
#include <iomanip>      // std::setbase

int main () {
  std::cout << std::setbase(16);
  std::cout << 110 << std::endl;
  return 0;
}

This code uses the setbase manipulator to set hexadecimal as the basefield selective flag.

Output:
6e


Data races

The stream object on which it is inserted/extracted is modified.
Concurrent access to the same stream object may introduce data races.

Exception safety

Basic guarantee: if an exception is thrown, the stream is in a valid state.

See also