Ubuntu16.04下vscode第一個C++程序

用vscode作爲自己用的編譯器,首先需要了解並掌握的就是配置文件。下面記錄的主要是配置文件,以及配置文件參數的意義。

main.cpp

#include<iostream>
using namespace std;
int main()
{
    cout << "Hello world!" << endl; 
    return 0;
}

tasks.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", //在launch.json文件中有用到
            "type": "shell",
            "command": "g++",
            "args": [
                "-g", "main.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

launch.json

//launch.json
{
    // 使用 IntelliSense 瞭解相關屬性。 
    // 懸停以查看現有屬性的描述。
    // 欲瞭解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",                                 //配置名稱,會在啓動配置的下拉菜單中顯示
            "type": "cppdbg",                                       //配置類型,只能爲cppdbg
            "request": "launch",                                    //請求類型,可以爲launch或attach
            "program": "${workspaceFolder}/a.out",                  //將要調試的程序的路徑
            "args": [],                                             //調試時傳遞給程序的命令行參數
            "stopAtEntry": false,                                   //設爲true程序會暫停在入口處
            "cwd": "${workspaceFolder}",                            //調試程序時的工作目錄
            "environment": [],                                      //環境變量
            "externalConsole": true,                                //調試時是否顯示控制檯窗口
            "MIMode": "gdb",                                        //指定連接的調試器,可以爲gdb或lldb
            "miDebuggerPath": "/usr/bin/gdb",                       //gdb路徑
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build"                                //調試開始前執行的任務,一般爲編譯程序
        }
    ]
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章