Cpp - cout Output numbers

Introduction

Manipulator
Effects
oct
Octal base
hex
Hexadecimal base
dec
Decimal base (by default)
showpos

Generates a + sign in non-negative numeric
output.
noshowpos

Generates non-negative numeric output
without a + sign (by default).
uppercase

Generates capital letters in hexadecimal
output.
nouppercase

Generates lowercase letters in hexadecimal
output (by default).

The following code reads integral decimal values and generates octal, decimal, and hexadecimal output.

Demo

#include <iostream>     // Declarations of cin, cout and 
using namespace std;    // manipulators oct, hex, ... 

int main() /*from www  .j  a  va  2 s .c om*/
{ 
    int number; 
    cout << "Please enter an integer: "; 
    cin >> number; 
    cout << uppercase                           // for hex-digits 
           << " octal  \t decimal  \t hexadecimal\n " 
           << oct << number << "       \t " 
           << dec << number << "       \t " 
           << hex << number << endl; 
    return 0; 
}

Result

Related Topics

Exercise