From 89cb027786fc18f3733dcbf161bd6a994074ee4b Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 15 Dec 2016 22:59:37 +0100 Subject: [PATCH] Ensure console output is UTF-8 under Windows --- CMakeLists.txt | 2 +- application/commandlineutils.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18a938b..210aacd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,7 +113,7 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_DESCRIPTION "Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities") set(META_VERSION_MAJOR 4) set(META_VERSION_MINOR 3) -set(META_VERSION_PATCH 0) +set(META_VERSION_PATCH 1) # find required 3rd party libraries include(3rdParty) diff --git a/application/commandlineutils.cpp b/application/commandlineutils.cpp index f47cdd7..a1f44b7 100644 --- a/application/commandlineutils.cpp +++ b/application/commandlineutils.cpp @@ -38,9 +38,8 @@ bool confirmPrompt(const char *message, Response defaultResponse) #ifdef PLATFORM_WINDOWS /*! - * \brief Starts the console. - * \remarks This method is only available on Windows and used to start - * a console from a GUI application. + * \brief Starts the console and sets the console output code page to UTF-8. + * \remarks This method is only available on Windows and used to start a console from a GUI application. */ void startConsole() { @@ -68,6 +67,9 @@ void startConsole() fp = _fdopen(conHandle, "w"); *stderr = *fp; setvbuf(stderr, NULL, _IONBF, 0); + // set console to handle UTF-8 IO correctly + SetConsoleCP(CP_UTF8); + SetConsoleOutputCP(CP_UTF8); // sync ios::sync_with_stdio(true); }