Wrote to a file using std::wofstream. The file remained empty

MSVC offers the codecvt_utf8 locale facet for this problem.

#include <codecvt>

// ...  
std::wofstream fout(fileName);
std::locale loc(std::locale::classic(), new std::codecvt_utf8<wchar_t>);
fout.imbue(loc);

Leave a Comment