Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Created November 30, 2017 12:16
Show Gist options
  • Select an option

  • Save Trass3r/08c42909b87be7a6a55e5eb0e8514a56 to your computer and use it in GitHub Desktop.

Select an option

Save Trass3r/08c42909b87be7a6a55e5eb0e8514a56 to your computer and use it in GitHub Desktop.
#ifdef _WIN32
#include <wincon.h>
#include <cstring>
#endif
static void setupUtf8Console()
{
#ifdef _WIN32
// set UTF8 code page
SetConsoleOutputCP(65001);
SetConsoleCP(65001); // probably does not work in practice
// set Unicode font
CONSOLE_FONT_INFOEX cfi = {};
cfi.cbSize = sizeof(cfi);
cfi.dwFontSize.Y = 14;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
memcpy(cfi.FaceName, L"Lucida Console", sizeof(L"Lucida Console"));
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
#endif
}
int main(int argc, const char** argv)
{
setupUtf8Console();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment