Windows 10pro
vscode version 1.25.1
Japanese is garbled at the terminal of vscode.I set "files.autoGuessEncoding":true
in the user settings, but it doesn't fix.What should I do?
I'm a beginner in programming, so I'm sorry if I said something strange.
"files.encoding": "shiftjis"
was added, but both the editor and terminal were garbled.
"terminal.integrated.shellArgs.windows": No characters were not printed when adding ["-NoExit", "chcp65001"]
to the configuration.
There are programs that work properly and programs that don't work.
"You can change the ""\n"" in the third image to ""endl""."
Also, when I try to write a new program just a while ago, a display like iostream file not found appears.It is still compiled and executed correctly.English characters are printed, but Japanese is not printed.
The "files.autoGuessEncoding" · "files.encoding" setting determines the encoding of the file.
You do not configure terminal encoding.
Solution 1
Change the terminal Powershell character code.
To change the character code, use the chcp command.
Run chcp65001
to change to UTF-8.
Run chcp932
to change to sjis.
Check the Microsoft document for the assigned number of each character code.
chcp
To automatically run at startup without manually entering the command
"terminal.integrated.shellArgs.windows":["-NoExit", "chcp65001"]
in the configuration file.
Solution 2
Powershell can be loaded without changing the settings if it is a SJIS, UTF-8BOM, UTF-16.
Change the encoding of the file to load.
Solution 1
Change the terminal Powershell character code.
To change the character code, use the chcp command.
Run chcp65001
to change to UTF-8.
Run chcp932
to change to sjis.
Check the Microsoft document for the assigned number of each character code.
chcp
To automatically run at startup without manually entering the command
"terminal.integrated.shellArgs.windows":[-NoExit", "chcp65001"]
in the configuration file.
Solution 2
Powershell can be loaded without changing the settings if it is a SJIS, UTF-8BOM, UTF-16.
Change the encoding of the file you want to import.
Click on the character code part of the bar below to save it with encoding→ Select the character code you want to save
Let's assume you're using MinGW64GCC.Visual Studio (Visual C++) is different.
To avoid confusion, remove all "files.encoding"
, "terminal.integrated.shellArgs.windows"
, "files.autoGuessEncoding"
, and restart Visual Studio Code.
Source code should be UTF-8 (If you also want to compile Visual C++ or want to see source code on PowerShell, use UTF-8 with BOM).The rest works by adding the -fexec-charset=CP932
option when compiling (both gcc and g++).
g++-fexec-charset=CP932 hello.cpp
Below is the explanation.
There is no standard character code in C/C++.Therefore, it may not work well if you do not specify the correct character code during compilation.The complicated thing is that the three character codes are used separately.They are as follows:
The compiler automatically converts the character code from 1. to 2. or 3.What these character codes are depends on your environment and compiler.
For MinGW64GCC
For Visual C++
Another thing to note is the behavior of printf
and iostream
.They deal with strings (char*
), but they do not perform character code conversion through the locale and print the data as it is.Therefore, if the character code of the string itself does not match the character code of the output destination, garbled characters will occur.(Wide string output may be character-coded to match the locale)
PowerShell in Visual Studio Code integrated terminal also has a character code, defaulting to locale dependency (CP932 in Japanese).In other words, the cause of garbled characters is that the character code in the string literal on the compiled binary in 2. does not match the character code in the terminal.
The GCC allows you to specify these three character codes at compile time.-fexec-charset=CP932
is the character code for the Japanese PoweShell.
[Supplement]
chcp65001
is the command.\
, such as 'Table'
.char*
Note that there is no character code information in itself.
Try changing the default character encoding from utf-8 to the character encoding that your file uses.
For example, if you want the default to Shift-JIS, add the following line after the line "files.autoGuessEncoding": true:
"files.encoding": "shiftjis",
© 2024 OneMinuteCode. All rights reserved.