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

相关推荐
rhythmcc2 小时前
【visual studio】visual studio配置环境opencv和onnxruntime
c++·人工智能·opencv
胖咕噜的稞达鸭2 小时前
数据结构---关于复杂度的基础解析与梳理
c语言·数据结构·算法·leetcode
十五年专注C++开发3 小时前
CMake进阶: externalproject_add用于在构建阶段下载、配置、构建和安装外部项目
linux·c++·windows·cmake·自动化构建
范纹杉想快点毕业3 小时前
《嵌入式 C 语言编码规范与工程实践个人笔记》参考华为C语言规范标准
服务器·c语言·stm32·单片机·华为·fpga开发·51单片机
長琹4 小时前
9、C 语言内存管理知识点总结
linux·c语言
码与农5 小时前
C++设计模式
开发语言·c++
Tipriest_5 小时前
CMake message()使用指南
c++·cmake·message
企鹅chi月饼6 小时前
c++中的Lambda表达式详解
c++·lambda
minji...6 小时前
算法题Day1
c++·算法
阿巴~阿巴~6 小时前
STL容器详解:Vector高效使用指南
开发语言·c++