1.安装gcc g++
sudo apt install gcc
sudo apt install g++
检查是否安装成功
gcc --verison
g++ --version
2.在vscode商店中安装c++插件
3.在根目录创建.vscode文件夹,然后写入配置文件
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true, //如果不要窗口弹出,在ide中显示,就设置成 false
"MIMode": "gdb",
"preLaunchTask": "build", //表示预先生成一个中间文件,用于g++运行
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-std=c++11",
"-o",
"${fileBasenameNoExtension}.out"
],
"problemMatcher": []
}
]
}
4.运行测试文件