Japanese garbled characters in the Clion console

Asked 2 years ago, Updated 2 years ago, 161 views

When I created Project C in Clion 2019.1.4, and ran the following program, the Japanese part of the execution result was translated into characters, which is troubling me.

#include<stdio.h>

int main() {
printf("Hello World");
return 0;
}

Run Results

 C:\Users\USERNAME\CLionProjects\untitled\cmake-build-debug\untitled.exe
上 up and down
Process finished with exit code 0

The source file is encoded as UTF-8.
I tried to change the encoding of the source file to ShiftJIS and it was fixed, but if possible, I would like to keep the encoding of the source file as UTF-8 and improve garbled characters.

Other things I've tried are as follows:

  • Add -Dconsole.encoding=UTF-8, -Dfile.encoding=UTF-8 to the end of the Custom VM Option.
  • Change settings Editor/Font, Editor/Color Scheme/Color Scheme Font, Editor/Color Scheme/Console Font to Source Han Code JPL

The operating system is Windows 10 Home Version 1803 Build 17134.829.

Probably because the source file is UTF-8 and the console is encoded as Shift JIS, I can't confirm it and I don't know how to deal with it.

How can I fix garbled characters?

Additional
Debugging instead of running showed no garbled characters.
Is the encoding different between the running console and the debugging console?
If possible, I would like to avoid garbled characters on the execution console.

windows c intellij-idea garbled-characters shift-jis

2022-09-30 19:24

1 Answers

The input and output have different character sets and must be explicitly specified.
Try adding the line below to MakeLists.txt.

set(CMAKE_CXX_FLAGS"${CMAKE_CXX_FLAGS}/execution-charset:SHIFT_JIS/source-charset:UTF-8")


2022-09-30 19:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.