vscode 配置c/c++环境 中文乱码

D:\MIscrobingDownload\mingw64\bin

mingw配置到环境变量中

测试一下,按win+r输入cmd打开终端

cpp 复制代码
gcc -v
g++ -v

安装插件


run code

因为run code 插件配置实质上是用它提供的指令进行编译执行,因此无法直接使用断点调试功能,需要对配置进行一定的更改

如果出现乱码问题

第一:

源文件 .cpp 修改为 UTF-8 编写和保存时的格式

第二:

OUTPUT输出时不乱码编译时 UTF-8格式

一 终端错误 terminal 改为UTF-8

可以找到code runner插件,点击扩展设置,随便点击一个打开setting.json文件,修改下配置命令

vscode 的设置里面的setting.json

在这里插入图片描述

配置 GBK 改为UTF-8 因为 UTF-8 能够兼容各种字符 终端输出中文不出错

总结:
terminal :
gbk编写和保存代码
终端 UTF-8 用 chcp 看 chcp 65001
OUTPUT
编写和保存代码用UTF-8
输出不乱码

设置

修改终端字体大小
terminal.integrated.fontSize

二 .cpp文件乱码 GBK

  1. c_cpp_properties.json
cpp 复制代码
{
    "configurations": [
        {
          "name": "Win32",
          "includePath": ["${workspaceFolder}/**"],
          "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
          "windowsSdkVersion": "10.0.17763.0",
          "compilerPath": "D:\\MIscrobingDownload\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe",   /*修改成自己bin目录下的g++.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
          "cStandard": "c11",
          "cppStandard": "c++17",
          "intelliSenseMode": "${default}"
        }
      ],
      "version": 4
}
  1. launch.json
cpp 复制代码
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\exe\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\MIscrobingDownload\\mingw64\\bin\\gdb.exe",// 自己的mingw gdb.exe
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",// 为 gdb 启用整齐打印
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "task g++"
        }  //,



// 生成 exe 文件
     /*   {
            "name": "C/C++: cpp.exe 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\Chromedownload\\mingw\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: cpp.exe 生成活动文件"
        }
*/
    ]
}
  1. settings.json
cpp 复制代码
{
    "files.associations": {
      "*.py": "python",
      "iostream": "cpp",
      "*.tcc": "cpp",
      "string": "cpp",
      "unordered_map": "cpp",
      "vector": "cpp",
      "ostream": "cpp",
      "new": "cpp",
      "typeinfo": "cpp",
      "deque": "cpp",
      "initializer_list": "cpp",
      "iosfwd": "cpp",
      "fstream": "cpp",
      "sstream": "cpp",
      "map": "c",
      "stdio.h": "c",
      "algorithm": "cpp",
      "atomic": "cpp",
      "bit": "cpp",
      "cctype": "cpp",
      "clocale": "cpp",
      "cmath": "cpp",
      "compare": "cpp",
      "concepts": "cpp",
      "cstddef": "cpp",
      "cstdint": "cpp",
      "cstdio": "cpp",
      "cstdlib": "cpp",
      "cstring": "cpp",
      "ctime": "cpp",
      "cwchar": "cpp",
      "exception": "cpp",
      "ios": "cpp",
      "istream": "cpp",
      "iterator": "cpp",
      "limits": "cpp",
      "memory": "cpp",
      "random": "cpp",
      "set": "cpp",
      "stack": "cpp",
      "stdexcept": "cpp",
      "streambuf": "cpp",
      "system_error": "cpp",
      "tuple": "cpp",
      "type_traits": "cpp",
      "utility": "cpp",
      "xfacet": "cpp",
      "xiosbase": "cpp",
      "xlocale": "cpp",
      "xlocinfo": "cpp",
      "xlocnum": "cpp",
      "xmemory": "cpp",
      "xstddef": "cpp",
      "xstring": "cpp",
      "xtr1common": "cpp",
      "xtree": "cpp",
      "xutility": "cpp",
      "stdlib.h": "c",
      "string.h": "c"
    },
    "editor.suggest.snippetsPreventQuickSuggestions": false,
    "aiXcoder.showTrayIcon": true
  }
  1. tasks.json 定义任务配置

再次强调:以后的C/C++代码文件必须放在这个Code文件夹里,或者说有.vscode文件夹的文件夹里,如果调试放在其他位置的代码文件会报错!

相关推荐
web_1553427465626 分钟前
性能巅峰对决:Rust vs C++ —— 速度、安全与权衡的艺术
c++·算法·rust
9毫米的幻想29 分钟前
【Linux系统】—— 冯诺依曼体系结构与操作系统初理解
linux·运维·服务器·c语言·c++
Mr.Wang8091 小时前
条款23:宁以non-member、non-friend替换member函数
开发语言·c++
汤永红1 小时前
在VSCode中接入deepseek
vscode·html·deepseek
以卿a2 小时前
C++ 模板初阶
开发语言·c++
USER_A0012 小时前
【C语言】第五期——函数
c语言
Hylan_J6 小时前
【VSCode】MicroPython环境配置
ide·vscode·python·编辑器
黑不溜秋的8 小时前
C++ 设计模式 - 策略模式
c++·设计模式·策略模式
李白同学8 小时前
【C语言】结构体内存对齐问题
c语言·开发语言
楼台的春风9 小时前
【MCU驱动开发概述】
c语言·驱动开发·单片机·嵌入式硬件·mcu·自动驾驶·嵌入式