Using hex, oct, dec and setbase stream manipulators. : int output « Data Type « C++






Using hex, oct, dec and setbase stream manipulators.

  
#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::hex;
using std::dec;
using std::oct;
using std::setbase;

int main()
{
   int n;

   cout << "Enter a decimal number: ";
   cin >> n;

   cout << n << " in hexadecimal is: " 
        << hex << n << '\n'
        << dec << n << " in octal is: " 
        << oct << n << '\n'
        << setbase( 10 ) << n << " in decimal is: " 
        << n << endl;

   return 0;
}
  
    
  








Related examples in the same category

1.Decimal in hexadecimal
2.Decimal in octal
3.Decimal in decimal
4.Display decimal value as hexadecimal value
5.Display decimal value as Octal value
6.Output integer with different base: 8, 10, 16
7.Right justification
8.Left justification
9.Use .(dot) as place holder
10.Set width of output
11.Printing an integer with internal spacing and forcing the plus sign.
12.Set showpos flag for decimal
13.Making I/O in Octal Format