From aaf3b23debc1fe1a06733c8c6468fb84233cc44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Sat, 8 Apr 2023 17:49:39 +0200 Subject: fix for windows utf-8 input (#840) Use UTF-16 as input on Windows, since UTF-8 does not work and reads multibyte characters as zeros --- examples/main/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'examples/main') diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 67a34e6..d59eeb4 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -386,10 +386,19 @@ int main(int argc, char ** argv) { std::string line; bool another_line = true; do { +#if defined(_WIN32) + std::wstring wline; + if (!std::getline(std::wcin, wline)) { + // input stream is bad or EOF received + return 0; + } + win32_utf8_encode(wline, line); +#else if (!std::getline(std::cin, line)) { // input stream is bad or EOF received return 0; } +#endif if (line.empty() || line.back() != '\\') { another_line = false; } else { -- cgit v1.2.3