Integral Stream Base: dec, oct, hex, showbase - C++ File Stream

C++ examples for File Stream:cout

Description

Integral Stream Base: dec, oct, hex, showbase

Demo Code

#include <iostream>

int main(int argc, const char *argv[]) {
    int x = 100;/*from   w  w  w. ja  va  2 s. co  m*/

    // use showbase to show number base
    std::cout << "Printing integers preceded by their base: " << std::endl
              << std::showbase;

    std::cout << x << std::endl;              // print decimal value
    std::cout << std::oct << x << std::endl;  // print octal value
    std::cout << std::hex << x << std::endl;  // print hexadecimal value

    return 0;
}

Result


Related Tutorials