#include <iostream>
#include <iomanip>

struct hex
{
    hex(int val) : value(val){ }
    int value;
};

std::ostream& operator<<(std::ostream& os, hex h)
{
    auto oldflags = os.flags();
    auto oldfill = os.fill();

    os.setf(std::ios::hex, std::ios::basefield);
    os.setf(std::ios::uppercase);
    os.fill('0');

    os << h.value;

    os.fill(oldfill);
    os.setf(oldflags);
    return os;
}

int main()
{
    for (int i = 0; i < 4; i++)
        std::cout << std::setw(5) << ' ' << std::setw(16) << hex(i) << std::endl;
}