Ubuntu Vscode how to write C ++ code
(A) Download Vscode
(1) Open the Ubuntu Software
(2) search Vscode, download and run.
(B) Install C ++
(1). See the list on the right, click on the bottom
(2). We then search for and download C ++ as well as C ++ Intellisense (auto completion)
(C) Configuration
(1) We return to the welcome screen, then select a directory ( Open Folder)
(2) We create a cpp file, and named 001.cpp
(3) Press F5, and then choose C ++
(4) This will pop up launch.json
(5) We modified this sentence
"program": "enter program name, for example ${workspaceFolder}/a.out",
Remove
enter program name, for example
(6) The launch.json closed, we returned 001.cpp.
(7) we press Ctrl + Shift + B, then pop up, then down we point, the last point of Other
(8) Then in the pop tasks.json, we modify the command entry.
"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 } } ] }