1.下载安装visual studio code
我的系统是Ubuntu20.04,首先是下载安装包。进入官网,直接下载压缩包。
https://code.visualstudio.com/Download
下载完成后双击安装即可。
2.C++运行环境配置
插件的安装
汉化:
过于简单,直接按照教程操作:https://jingyan.baidu.com/article/7e44095377c9d12fc1e2ef5b.html
3.新建项目并运行:
我在主目录建了一个新的文件夹,名为VSCode
然后使用VS打开它,参考图片:
新建main.cpp文件并输入程序:
参考程序:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world" << endl;
getchar();
return 0;
}
然后点击左边的运行按钮,点击运行和调试,
选择C++(GDB/LLDB):
然后选择gcc:
直接运行一下,会出错,但是文件那边会多出一个tasks.json和launch.json文件,如果没有,手动创建两个文件,这个也是我们需要修改的文件,修改为如下内容:
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"]
}]
}
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) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "build",
"setupCommands": [{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}]
}]
}
每一次运行都返回到cpp代码界面,注意退出上一次的运行.
再一次返回cpp界面,点击运行或者按下F5
到这里C++ 代码就在Ubuntu20.04上跑起来了。环境搭建完成,就可以进行激动人心的学习了。
参考文章:
https://blog.csdn.net/qq_40495217/article/details/91351470
https://jingyan.baidu.com/article/7e44095377c9d12fc1e2ef5b.html
https://sidney.blog.csdn.net/article/details/111938091?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&dist_request_id=e2ed650b-01a6-4d80-bd9c-42ab59ac7f48&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control