example3_base_manipulation.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <iomanip>

int main() {
    int number = 255;

    std::cout << "Decimal: " << number << std::endl;
    std::cout << "Hexadecimal: " << std::hex << number << std::endl;
    std::cout << "Octal: " << std::oct << number << std::endl;

    std::cout << "\nFormatted output:" << std::endl;
    std::cout << std::setfill('0');
    std::cout << "Decimal: " << std::dec << std::setw(10) << number << std::endl;
    std::cout << "Hexadecimal: 0x" << std::hex << std::setw(8) << number << std::endl;
    std::cout << "Octal: 0" << std::oct << std::setw(11) << number << std::endl;

    return 0;
}
Back to iomanip