日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯網營銷解決方案
Ubuntu下VSCode如何調試C++代碼

最近開始在ubuntu下使用Vs Codel,真的方便,可以和git結合。下面總結一下如何調試程序,

創(chuàng)新互聯公司10多年成都定制網頁設計服務;為您提供網站建設,網站制作,網頁設計及高端網站定制服務,成都定制網頁設計及推廣,對成都搬家公司等多個方面擁有多年的網站維護經驗的網站建設公司。

我寫了一個實例程序(不重要)

#include
#include
#include
#include
#include
using namespace std;
int main(void)
{
    fstream iofile("test.txt");
    vector strs(20);
    int i=0;
    if(!iofile){
        cerr<<"open file failed"<    }else{
        while(iofile>>strs[i++]);
    }
    for(int j=0;j    {
        cout<    }
//    cout<    cout<<"after sort"<    cout<<*(strs.begin())<    sort(strs.begin(),strs.begin()+i-1);
    cout<<"i:"<    for(int j=0;j        {
                cout<        }
    cout<    return 0;
}

這個時候,我們按F5,發(fā)現不能運行,它提示需要一個Launch.json文件,OK,這是一個啟動文件,我們來配置它。

{
    // 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}/build",
            "preLaunchTask": "build",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

注意,這里需要修改的部分主要是program那一行,僅需修改為自己編譯后產生的文件名,不如g++ -g 1.7.cpp -o build,所以這里我就取了build這個名字。

還有,就是要添加preLaunchTask這一行,名字與下面的task要對應。

這里,它還需要一個task.json文件,配置如下,

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${workspaceFolder}/chapter01/1.7.cpp",
                "-o",
                "build"
            ]
        }
    ]
}

大家可以看到,這里只需要將label的值要與上面的preLaunchTask相對應,其他的就是命令行部分,完成這個文件后,我們ctrl+shift+b,這是會執(zhí)行task。

之后,我們打開main文件,設置斷點,F5即可開始調試代碼。

關于Launch.json:

官方是這樣說的:However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details. VS Code keeps debugging configuration information in a launch.json file located in a .vscode folder in your workspace (project root folder) or in your user settings or workspace settings.但是,對于大多數調試方案,創(chuàng)建啟動配置文件是有益的,因為它允許您配置和保存調試設置詳細信息。 VS Code將配置信息保存在位于工作區(qū)(項目根文件夾)的.vscode文件夾或用戶設置或工作區(qū)設置中的launch.json文件中。

個人感覺可能是項目比較簡單所以看不來它的好處。


當前標題:Ubuntu下VSCode如何調試C++代碼
URL分享:http://www.dlmjj.cn/article/djhisio.html