Ubuntu如何使用Vscode写C++代码
(一). 下载Vscode
(1). 打开Ubuntu软件
(2). 搜索Vscode,下载并运行.
(二). 安装C++
(1). 看到右边的列表,点击最下面的
(2). 然后我们搜索和下载 C++ 还有 C++ Intellisense(自动补全)
(三). 配置
(1). 我们回到欢迎界面,然后选择一个目录(Open folder)
(2). 我们创建一个cpp文件,并且命名为001.cpp
(3). 按下F5,然后选择C++
(4). 这个时候会弹出launch.json
(5). 我们修改这一句
"program": "enter program name, for example ${workspaceFolder}/a.out",
去掉
enter program name, for example
(6)把launch.json关闭,我们回到001.cpp.
(7) 我们按下Ctrl + Shift + B ,然后会弹出,然后我们往下点,最后点Other
(8) 然后在弹出的tasks.json中,我们修改command项.
"command": "echo Hello"
修改为:
"command": "g++ -g -o a.out ${file}"
(9) 然后我们就可以关闭 返回001.cpp了。
(10) 我们按下 Ctrl + Shift + B 编译文件 然后再按下F5运行程序.
最后附上完好的
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}/a.out", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
tasks.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "g++ -g -o a.out ${file}", "group": { "kind": "build", "isDefault": true } } ] }