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文件夹的文件夹里,如果调试放在其他位置的代码文件会报错!

相关推荐
7yewh17 分钟前
【LeetCode】力扣刷题热题100道(6-10题)附源码 相交链表 回文链表 反转链表 合并链表 移动零(C++)
c语言·数据结构·c++·算法·leetcode·链表·贪心算法
程序员老冯头21 分钟前
第三十六章 C++ Web 编程
开发语言·c++·microsoft
bohu8329 分钟前
4.5 在C++节点中使用参数
c++·ros2·参数通信
DARLING Zero two♡33 分钟前
【优选算法】Simulation-Phoenix:模拟算法的重生涅槃
java·数据结构·c++·算法·leetcode
小林熬夜学编程37 分钟前
【Linux网络编程】第二十二弹---深入理解 I/O 多路转接之 epoll:系统调用、工作原理、代码演示及应用场景
linux·运维·服务器·开发语言·网络·c++
YANQ6621 小时前
9.3 opencv对图片的分割处理(c++)
开发语言·c++
Happy_Enger8 小时前
详述 VScode &wkhtmltopdf 实现 markdown 转带目录标签(导航栏)的 PDF
vscode·pdf·目录·导航栏·wkhtmltopdf
凌冰_8 小时前
Vscode 安装、配置及插件
ide·vscode·编辑器
Bonway_Huang8 小时前
VSCode 中的 launch.json 配置使用
ide·vscode·json
17´9 小时前
使用QT+OpenCV+C++完成一个简单的图像处理工具
c++·图像处理·qt·opencv