#include <ostream>
#include <iostream>
#include <locale>

using namespace std;

inline int geti() { 
    static int i = ios_base::xalloc();
    return i;
}

// rename it to something better
struct my_num_put : num_put<char> {
    static const std::ios_base::fmtflags reqFlags
    	= (std::ios_base::showbase | std::ios_base::hex);

    iter_type 
    do_put(iter_type s, ios_base& f, char_type fill, long v) const {
        if (v == 0 && ((f.flags() & reqFlags) == reqFlags)) {
            *(s++) = '0';
            *(s++) = 'x';
        }
        return num_put<char>::do_put(s, f, fill, v);
    } 

    iter_type 
    do_put(iter_type s, ios_base& f, char_type fill, unsigned long v) const { 
          if (v == 0 && ((f.flags() & reqFlags) == reqFlags)) {
            *(s++) = '0';
            *(s++) = 'x';
        }
        return num_put<char>::do_put(s, f, fill, v);
    } 
}; 

int main() {
	// wrong
    std::cout << std::showbase << std::hex << 0 << ' ' << 11 << std::endl;
    
    // fixed by workaround
    std::cout.imbue(std::locale(std::locale(), new my_num_put));
    std::cout << std::showbase << std::hex << 0 << ' ' << 11 << std::endl;
    
    // sanity check
    std::cout.unsetf(my_num_put::reqFlags);
	std::cout                              << 0 << ' ' << 11 << std::endl;

	return 0;
}