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).
- all is on windows 11
- the .c file is utf-8 format
- 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:
- 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.
- 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.