Quantcast
Channel: Active questions tagged charset - Stack Overflow
Viewing all articles
Browse latest Browse all 59

How to set vscode terminal charset(for decoding) to GBK, or set vscode gcc build task use "-fexec-charset=UTF-8"

$
0
0

When i use the button "run C/c++ file" to run a ".c" file, and i got wrong characters in my terminal(default by powershell).

  1. all is on windows 11
  2. the .c file is utf-8 format
  3. after run task finished, i inputed "chcp" in the named "cppdbg" terminal, and i got "65001"(UTF-8), so i gusses the ordinary outputs is encoded by "936"(GBK).

in other words, the ordinary outputs is encoded by "936"(GBK) and the "cppdbg" terminal decode with "65001"(UTF-8), so they are not matched correctly.

I know there is two ways to fix this problem:

  1. Set "gcc" to complile with arg "-fexec-charset=UTF-8", then i set it in task.json like
"args": ["-fdiagnostics-color=always","-fexec-charset=UTF-8","-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe"            ]

but it does not work. and i use gcc to compile and link directly rather than using the vscode button "run C/c++ file", Nodoubtedly it works.

  1. Set the "cppdbg" terminal decoding to "936", i tred to set it in setting.json like
"terminal.integrated.profiles.windows": {"PowerShell": {"source": "PowerShell","icon": "terminal-powershell","args": ["-NoExit","\C","chcp 936"]        }}

but it also does not work, "chcp 936" executed absolutely, but there is something hided in the button "run C/c++ file", still show wrong character and input "chcp" will get "65001" not "936"

Finally i use a extension named "code runner", and set gcc arg "-fexec-charset=UTF-8", it works,and i want to know why both solution 1 and 2 which i mentioned above are not work.


Viewing all articles
Browse latest Browse all 59

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>