I need precise Unicode-output to the console. If I imbue wcout to "en_US.UTF8" the characters are mapped to UTF-8 but they arent correctly displayed by the console. So I wrote a little helper function:
void writeOutput( wchar_t const *str, bool err )
{
static mutex mtx;
lock_guard<mutex> lock( mtx );
wstringstream wss;
wss << str << L"\n";
wstring strFmt = move( wss.str() );
DWORD dwWritten;
WriteConsoleW( GetStdHandle( !err ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE ), strFmt.c_str(), wcslen( strFmt.c_str() ), &dwWritten, nullptr );
}
This function correctly displays the Unicode-characters. But if I do I/O-redirection with "program > outfile" nothing is written in the file. So how do I detect that's there a redirection?