I think the first thing that should be addressed is that the std::codecvt
family facets are only used by std::basic_filebuf
because code conversion is only needed when dealing with an external device. In your code, you were imbuing the locale into std::cin
, which has a buffer that does not do code conversion.
Of course, it is still possible to perform code conversion within the program, but the thing about your facet that was preventing your code from working was that it inherited from a specialization of std::codecvt<>
that cannot do conversions. The char => char
specialization of std::codecvt<>
doesn't define a conversion, therefore do_in()
won't be called because it is unnecessary to convert between the two types.
I tried running your code, but changing the inherited facet to std::codecvt<wchar_t, char, std::mbstate>
and used wide-character file streams and it worked.
If you want this to work for narrow-character streams as well I would suggest creating a stream buffer that forwards uppercase characters through underflow()
.