A manipulator: turns on the showbase flag and sets output to hexadecimal : cout custom « Console « C++






A manipulator: turns on the showbase flag and sets output to hexadecimal


#include <iostream>
#include <iomanip>
using namespace std;

ostream &sethex(ostream &stream)
{
  stream.setf(ios::showbase);
  stream.setf(ios::hex, ios::basefield);
  return stream;
}
int main()
{
  cout << 256 << " " << sethex << 256;
  return 0;
}

           
       








Related examples in the same category

1.Create an output manipulator. Create an output manipulator.
2.A simple output manipulator: sethexA simple output manipulator: sethex
3.Define operator for coutDefine operator for cout
4.Create custom output formatCreate custom output format
5.Custom cout output manipulatorCustom cout output manipulator