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

相关推荐
Merokes7 小时前
关于Gstreamer+MPP硬件加速推流问题:视频输入video0被占用
c++·音视频·rk3588
MonkeyKing_sunyuhua7 小时前
Visual Studio Code 进行汉化
ide·vscode·编辑器
沫夕残雪7 小时前
HTTP,请求响应报头,以及抓包工具的讨论
网络·vscode·网络协议·http
请来次降维打击!!!8 小时前
优选算法系列(5.位运算)
java·前端·c++·算法
别NULL8 小时前
机试题——统计最少媒体包发送源个数
c++·算法·媒体
嘤国大力士8 小时前
C++11&QT复习 (七)
java·c++·qt
背影疾风9 小时前
C++学习之路:指针基础
c++·学习
x-cmd9 小时前
[250331] Paozhu 发布 1.9.0:C++ Web 框架,比肩脚本语言 | DeaDBeeF 播放器发布 1.10.0
android·linux·开发语言·c++·web·音乐播放器·脚本语言
还是鼠鼠9 小时前
Node.js全局生效的中间件
javascript·vscode·中间件·node.js·json·express
myloveasuka9 小时前
[Linux]从硬件到软件理解操作系统
linux·开发语言·c++