C++ iomanip Library - setbases Function


Advertisements

Description

The C++ function std::setbases 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 is used to sets the basefield to one of its possible values: dec, hex or oct, according to argument base.

Declaration

Following is the declaration for std::setbases function.

setbase (int base);

Parameters

base − Numerical radix to be used as shown below −

base − Numerical radix to be used as shown below −

Sr.No. base argument & same as inserting
1

8

oct

2

10

dec

3

16

hex

4

any other

resetiosflags(ios_base::basefield)

Return Value

It returns unspecified. This function should only be used as a stream manipulator.

Exceptions

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

Data races

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

Example

In below example explains about setbase function.

#include <iostream>
#include <iomanip>

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

Let us compile and run the above program, this will produce the following result −

6e
iomanip.htm
Advertisements