setbase

To set the numeric base of an output.

smanip setbase(int)

Remarks

The manipulator setbase() directly sets the numeric base of integral output to the stream. The arguments are in the form of 8, 10, 16, or 0, and 8 octal, 10 decimal and 16 hexadecimal. Zero represents ios::basefield; a combination of all three.

Returns a smanip type, which is an implementation defined type.

See Also

ios_base::setf()

Listing: Example of setbase usage:
#include <iostream>
#include <iomanip>

int main()
{
using namespace std;
   cout << "Hexadecimal "
      << setbase(16) << 196 << '\n';
   cout << "Decimal " << setbase(10)       << 196 << '\n';
   cout << "Octal " <<setbase(8) << 196 << '\n';
   cout.setf(ios::hex, ios::oct | ios::hex);
   cout << "Reset to Hex " << 196 << '\n';
   cout << "Reset basefield setting "
      << setbase(0) << 196 << endl;
   return 0;
}

Result:

  Hexadecimal c4
  Decimal 196
  Octal 304
  Reset to Hex c4
  Reset basefield setting 196