I am redirecting std::wclog
to a file for logging in my program:
std::wclog.rdbuf((new std::wofstream("C:\\path\\to\\file.log", std::ios::app))->rdbuf());
Logging happens by writing to std::wclog
:
std::wclog << "Schöne Grüße!" << std::endl;
Surprisingly I found that the file is being written in ANSI. (This would be totally acceptable for ofstream
and clog
, but I had expected wofstream
and wclog
to produce some kind of unicode output.) I want to be able to log in CYK langugages as well (e.g. user input), so is there a way to get wofstream
to produce UTF-8? The openmode flags seem not to provide for this.
(If there isn’t a platform-independent way, I am on Win7+ 64-bit.)
Edit:
There is an error in the question above. The line
std::wclog << "Schöne Grüße!" << std::endl;
should correctly be
std::wclog << L"Schöne Grüße!" << std::endl;
This is just to demonstrate what I want to do, in real life the wstring
being written to the wofstream
comes out of a class which provides for translation, like
std::wclog << _(L"Best regards") << std::endl;
where
#define _(X) i18n::translate(X)
class i18n {
public:
static std::wstring translate(const std::wstring&);
}
So what I want to do is to write a wstring
to std::wclog
using an wofstring
to put it into a file, and that file should be UTF-8 encoded (without BOM).