如图所示,绿色框部分就是正常出现的中文,蓝色框部分出现的就是乱码的中文信息。
task.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "gcc.exe build active file",
"command": "E:/MinGW/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-fexec-charset=utf-8",
"-finput-charset=UTF-8",
"-g",
// "${file}",
"${fileDirname}\\*.c",
"-Wall",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"chcp":"65001",
"cwd": "E:/MinGW/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"chcp":"65001",
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
setting.json:
{
"workbench.colorTheme": "Default Dark+",
"C_Cpp.vcFormat.newLine.beforeOpenBrace.block": "sameLine",
"C_Cpp.vcFormat.space.pointerReferenceAlignment": "right",
"[c]": {
"editor.defaultFormatter": "ms-vscode.cpptools",
"files.encoding": "utf8"
},
"editor.defaultFormatter": "ms-vscode.cpptools",
"editor.formatOnType": true,
"C_Cpp.formatting": "vcFormat",
"code-runner.runInTerminal": true,
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"editor.formatOnSave": true,
"C_Cpp.vcFormat.indent.caseLabels": true,
"C_Cpp.vcFormat.indent.accessSpecifiers": true,
"C_Cpp.vcFormat.newLine.beforeOpenBrace.function": "newLine",
"C_Cpp.vcFormat.newLine.beforeOpenBrace.namespace": "sameLine",
"C_Cpp.vcFormat.newLine.beforeOpenBrace.type": "sameLine",
"C_Cpp.vcFormat.newLine.beforeOpenBrace.lambda": "sameLine",
"editor.fontLigatures": false,
"terminal.integrated.profiles.windows": {
"Command Prompt": {
"path": "C:\\Windows\\System32\\cmd.exe",
"args": ["-NoExit", "/K", "chcp 936"]
},
"PowerShell": {
"path": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": ["-NoExit", "/K", "chcp 65001"]
}
},
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc *.c -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
"python": "python -u",
"perl": "perl",
"perl6": "perl6",
"ruby": "ruby",
"go": "go run",
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
"vbscript": "cscript //Nologo",
"typescript": "ts-node",
"coffeescript": "coffee",
"scala": "scala",
"swift": "swift",
"julia": "julia",
"crystal": "crystal",
"ocaml": "ocaml",
"r": "Rscript",
"applescript": "osascript",
"clojure": "lein exec",
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
"racket": "racket",
"scheme": "csi -script",
"ahk": "autohotkey",
"autoit": "autoit3",
"dart": "dart",
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
"haskell": "runhaskell",
"nim": "nim compile --verbosity:0 --hints:off --run",
"lisp": "sbcl --script",
"kit": "kitc --run",
"v": "v run",
"sass": "sass --style expanded",
"scss": "scss --style expanded",
"less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
"FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"sml": "cd $dir && sml $fileName"
},
"C_Cpp.loggingLevel": "Warning",
"code-runner.languageIdToFileExtensionMap": {
"bat": ".bat",
"powershell": ".ps1",
"typescript": ".ts"
},
"editor.tabSize": 4,
"files.autoGuessEncoding": true,
"files.encoding": "utf8bom",
"C_Cpp.default.cStandard": "c11",
"debug.onTaskErrors": "showErrors",
"code-runner.saveFileBeforeRun": true,
}
cmd终端字符集是 UTF-8
Powershell终端字符集是 UTF-8
vscode编码的字符集也是UTF-8
环境变量中,用户变量和环境变量我都加上了字符集的设置
首先,请确保你已经设置了终端输出的字符集为 UTF-8。您可以在 task.json 文件中检查是否已经配置,它应该包含以下内容:
"command": "${command:pickRemoteProcess}",
"args": [],
"options": {
"cwd": "${workspaceFolder}",
"env": {
"LANG": "zh_CN.UTF-8",
"LC_ALL": "zh_CN.UTF-8"
}
}
您还需要确保输入输出的字符集都是 UTF-8。您可以在 vscode 中的 terminal 中运行以下命令来检查字符集:
ruby
Copy code
$ locale
如果上述设置和命令都没有解决问题,您可以在 .vscode/settings.json 中添加以下内容:
json
Copy code
"terminal.integrated.fontFamily": "simsun.ttc",
"terminal.integrated.fontSize": 12,
"terminal.integrated.drawBoldTextInBrightColors": true,
"terminal.integrated.drawBoldTextInBrightColors": true,
"terminal.integrated.rendererType": "dom"
同时,您需要确保您的系统环境变量 LANG 的值为 UTF-8 编码。
如果仍然无法解决问题,请尝试更改字体。您可以在 VSCode 中设置 terminal.integrated.fontFamily 为其他字体,例如 simsun.ttc,并再次尝试。
希望这些信息能够帮助您解决问题。
不知道你这个问题是否已经解决, 如果还没有解决的话: