0、环境配置
参考:https://blog.csdn.net/qq_34347375/article/details/80851417
博主环境:linux + vs-code
1、GCC
1)查看gcc版本
$ gcc -v
如果本地有gcc,如图所示
2)如果没有就下载安装gcc
$ sudo apt-get install gcc
2、VScode 安装插件
1) 进入vscode,点这个
2)在搜索框搜索以下四个插件,并点击安装
C/C++、 C++ Intellisense、 Code Runner 和 Include Autocomplete
在位置1搜索以上四个插件的名字,然后点击安装
3、创建helloworld.cpp文件
创建文件夹和文件(可以没有文件夹),然后写helloworld的内容
#include
#include
using namespace std;
int main()
{
cout << “hello world”<<endl;
return 0;
}
4、配置信息
1、通过快捷键Ctrl+Shift+P打开搜索栏,搜索Edit configuration,打开“c_cpp_properties.json”文件,
注意:
“compilerPath”: “/usr/bin/gcc”,如果你的gcc路径不是这个的话就需要在终端里使用whereis gcc去查看gcc的路径
Ctrl+Shift+P
Edit configuration
c_cpp_properties.json
{
“configurations”: [
{
“name”: “Linux”,
“includePath”: [
“${workspaceFolder}/**”
],
“defines”: [],
“compilerPath”: “/usr/bin/gcc”,
“cStandard”: “gnu17”,
“cppStandard”: “gnu++14”,
“intelliSenseMode”: “linux-gcc-x64”
}
],
“version”: 4
}
2、构建代码
如果你想从VS Code构建你的应用程序,你需要生成一个tasks.json文件;
打开命令面板(Ctrl + Shift + P), 搜索Configure Tasks命令,单击从模板创建tasks.json文件,您将看到任务运行模板列表,选择Others, 然后修改内容
{
“version”: “2.0.0”,
“tasks”: [
{
“label”: “build”,
“type”: “shell”,
“command”:“g++”,
“args”: [
“-g”, “helloworld.cpp”
],
“group”: {
“kind”: “build”,
“isDefault”: true
}
}
]
}
3、用户配置
打开命令面板(Ctrl + Shift + P),搜索用户设置,在弹出的界面搜索code-runner.runInTerminal,在选项前打对勾
至此,在屏幕右上角点击三角型,就可以运行了
END