View Single Post
Old 30th September 2011, 22:52   #1006  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Sorry, yet another suggestion

Code:
    //Initialize terminal (to fix Unicode output on Win32)
    #if defined(_MSC_VER) && defined(UNICODE)
        _setmode(_fileno(stdout), _O_U8TEXT);
        _setmode(_fileno(stderr), _O_U8TEXT);
        if(_ftelli64(stdout) == 0I64) fwprintf(stdout, L"\uFEFF");
        if(_ftelli64(stderr) == 0I64) fwprintf(stderr, L"\uFEFF");
    #endif
This will prepend a proper BOM (Byte Order Mark), iff the output is redirected to (an empty) file. Some text editors need this, to recognize the file as UTF-8.
Always writing the BOM is not a good idea, because we might be redirecting to a non-empty file and we don't want the BOM somewhere in the middle of the file.
Also we don't want to write a BOM to the console, as it produces an ugly ▯ character. But this won't happen, because _ftelli64() will return -1 in that case.
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊
LoRd_MuldeR is offline   Reply With Quote