unbutu下安装VScode后配置c++和python
1.下载VScode,并在终端安装g++和python3
我是在软件商店下载的VScode,下载完成之后需要确保你的linux系统安装了g++和python3
查看版本命令:
g++ --version
python3 --version
下载命令:
sudo apt install g++
sudo apt install python3
接着安装几个插件,flake8(错误检查)和yapf(美化代码)插件
sudo apt-get install python-pip
pip install flake8
pip install yapf
2.需要安装一些VScode插件
下载的位置在左边一列最下面的小方块
Chinese 汉化
C/C++
python
以上是必须要安装的,下面几个是为了以后使用方便。
Auto Close Tag 匹配标签,关闭对应的标签。
Path Autocomplete 路径智能补全
Material Theme 主要是改变背景颜色、代码高亮和字体。
vscode-icons 使得文件结构更加清晰
Bracket Pair Colorizer 2 括号高亮3.开始创建第一个工程
VScode是以文件夹的形式管理工程的,因此我们首先新建一个文件夹,我这里取名CODE
在VScode中通过“文件“选项的“打开文件夹”打开CODE,并新建文件main.cpp和p1.py
这两个分别是C文件和py文件。
输入最简单打印hello world代码后,保存,运行,出现以下界面,
在这里插入图片描述
然后是,
选择第一个,然后会有打开launch.json的选项或者是直接跳转的
先放出我的launch.json和tasks.json(基本上复制粘贴就能用)
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python3",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"console": "integratedTerminal"
},
{
"name": "gdb",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.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(g++)",
}
]
}
tasks.json
{
"tasks": [
{
"label": "build(g++)",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-std=c++11",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out"
]
},
{
"label": "python3",
"type": "shell",
"command": "python3",
"args": [
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "shared"
},
}
],
"version": "2.0.0"
}
说一些注意事项:
1.为了F5之后直接在终端显示结果,而不在VSvscode里输入一些其他的命令才能出结果,
“externalConsole”: true,这里要改为true,
2.launch.json中"preLaunchTask": “build(g++)”,一项双引号里的内容要和tasks.json中"label": “build(g++)”,内容一样,否则找不到任务,
3.tasks.json中g++的 “args”: [
“-g”,
“{fileDirname}/${fileBasenameNoExtension}.out”
]
要加"-std=c++11",这也是让C++结果显示在终端的一步。
4.每次修改文件后,无论是代码文件还是.json文件都要保存
C运行结果
python运行结果