Using hex, oct, dec and setbase stream manipulators. : cout dec oct hex « Development « C++ Tutorial






#include <iostream>
#include <iomanip>
using namespace std;
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;
}








5.4.cout dec oct hex
5.4.1.cout: hex
5.4.2.cout: oct
5.4.3.cout: dec
5.4.4.To output in hexadecimal
5.4.5.Using hex, oct, dec and setbase stream manipulators.