安装配置C++环境
1、下载安装MinGW
https://sourceforge.net/projects/mingw-w64/files/
搜索x86_64-posix-seh最新版
2、环境变量配置
C:\mingw64 当前MinGW安装目录
VS Code相关配置
1、安装C/C++扩展插件
2、新建cpp文件
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
system("chcp 65001");
string name;
cout << "请输入您的名称: ";
cin >> name;
cout << "您的名称是: " << name << endl;
while(1);
}
3、配置文件修改
F5选择C++ GDB
然后选择g++.exe
launch.json文件
注意:miDebuggerPath路径和preLaunchTask值(需要和tasks.json的label相同)
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
tasks.json文件
注意:label值和command路径以及options里的cwd路径
{
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\mingw64\\bin"
}
}
],
"version": "2.0.0"
}