diff options
author | Tomáš Pazdiora <tomas.pazdiora@gmail.com> | 2023-04-08 17:49:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-08 17:49:39 +0200 |
commit | aaf3b23debc1fe1a06733c8c6468fb84233cc44f (patch) | |
tree | c18392a399ef7369b5df1719ab7547e649408bb7 /examples/main | |
parent | f2d1c472946dee2aba9077e8df73346796752b10 (diff) |
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
Diffstat (limited to 'examples/main')
-rw-r--r-- | examples/main/main.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
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 { |