Read input for Decimal, Octal and Hexadecimal Values - C++ Data Type

C++ examples for Data Type:int

Description

Read input for Decimal, Octal and Hexadecimal Values

Demo Code

#include <iomanip>
#include <iostream>

int main(int argc, const char *argv[]) {
    int intDec, intOct, intHex = 0;

    std::cout << "Enter 3 ints in decimal, octal and hexadecimal formats: ";
    std::cin >> intDec >> intOct >> intHex;

    std::cout << std::left << std::setw(6) << "dec" << std::setw(6) << "oct" << std::setw(3) << "hex\n";

    std::cout << std::setw(6) << std::dec << intDec << std::setw(6) << std::oct << intDec << std::setw(6) << std::hex << intDec << "\n";

    std::cout << std::setw(6) << std::dec << intOct << std::setw(6) << std::oct << intOct << std::setw(6) << std::hex << intOct << "\n";

    std::cout << std::setw(6) << std::dec << intHex << std::setw(6) << std::oct << intHex << std::setw(6) << std::hex << intHex << "\n";

    return 0;/*from www. j a v  a2s  .c  om*/
}

Result


Related Tutorials