一、安装VScode
在ubuntu中找到Ubuntu Software
点击右上角弹出搜索框并搜索vscode,进去后点击install下载
二、环境构建
打开VScode,在搜索栏中搜索C/C++,并点击install进行插件的下载
选择打开一个文件夹,并在文件夹中新建一个文件hello.cpp
输入代码:
#include<iostream>
using namespace std;
int main()
{
cout<<"hello world!"<<endl;
return 0;
}
搭建环境
完成后会得到默认生成的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": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",q
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
生成tasks.json文件
然后将其中的代码替换成以下代码:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-std=c++11",
"-o",
"${fileBasenameNoExtension}.out"
]
}
]
}
然后即可在.cpp文件中开始调试