打开 Ubuntu 自带的如下软件,在搜索栏直接搜索下载 Visual Studio Code
下载网址:点击此处跳转下载界面
点击下载完成的压缩包,右侧的小图标
在文件夹中对其进行解压
在终端输入如下指令
sudo dpkg -i code_1.60.0-1630494279_amd64.deb
如果此处报如下错误,点击此处跳转进行解决
解压完成
可以找到已经安装完成的 VS Code
运行如下指令可得到版本号,意味着安装成功
code --version
code
mkdir ~/Projects //home目录下创建Projects文件夹
mkdir ~/Projects/cpp_test && cd ~/Projects/cpp_test //Projects文件夹下创建cpp_test文件夹,并到此文件夹下
mkdir ./.vscode
cat > .vscode/tasks.json << EOF
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-std=c++17",
"-Wall",
"-Wextra",
"-g",
"-ggdb",
"main.cpp",
"-o",
"demoapp.out"
],
"group": "build",
"presentation": {
"reveal": "always",
},
"problemMatcher": "\$gcc"
}
]
}
EOF
cat > .vscode/launch.json << EOF
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "\${workspaceFolder}/demoapp.out",
"args": [],
"stopAtEntry": false,
"cwd": "\${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}
EOF
if [ `getconf LONG_BIT` -eq "64" ]; then
cat > .vscode/c_cpp_properties.json << EOF
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/usr/include/c++/8",
"/usr/include/x86_64-linux-gnu/c++/8",
"/usr/include/c++/8/backward",
"/usr/lib/gcc/x86_64-linux-gnu/8/include",
"/usr/local/include",
"/usr/lib/gcc/x86_64-linux-gnu/8/include-fixed",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include/c++/8",
"/usr/include/x86_64-linux-gnu/c++/8",
"/usr/include/c++/8/backward",
"/usr/lib/gcc/x86_64-linux-gnu/8/include",
"/usr/local/include",
"/usr/lib/gcc/x86_64-linux-gnu/8/include-fixed",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}
EOF
else
cat > .vscode/c_cpp_properties.json << EOF
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/usr/include/c++/8",
"/usr/include/i386-linux-gnu/c++/8",
"/usr/include/c++/8/backward",
"/usr/lib/gcc/i686-linux-gnu/8/include",
"/usr/local/include",
"/usr/lib/gcc/i686-linux-gnu/8/include-fixed",
"/usr/include/i386-linux-gnu",
"/usr/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include/c++/8",
"/usr/include/i386-linux-gnu/c++/8",
"/usr/include/c++/8/backward",
"/usr/lib/gcc/i686-linux-gnu/8/include",
"/usr/local/include",
"/usr/lib/gcc/i686-linux-gnu/8/include-fixed",
"/usr/include/i386-linux-gnu",
"/usr/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}
EOF
fi
touch main.cpp
code .
#include
int main(void)
{
std::cout << "Hello World!" << std::endl;
return 0;
}
在终端输入以下内容,运行程序
./demoapp.out