日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Ubuntu下VSCode如何調(diào)試C++代碼

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

創(chuàng)新互聯(lián)公司10多年成都定制網(wǎng)頁設(shè)計(jì)服務(wù);為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計(jì)及高端網(wǎng)站定制服務(wù),成都定制網(wǎng)頁設(shè)計(jì)及推廣,對(duì)成都搬家公司等多個(gè)方面擁有多年的網(wǎng)站維護(hù)經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。

我寫了一個(gè)實(shí)例程序(不重要)

#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;
}

這個(gè)時(shí)候,我們按F5,發(fā)現(xiàn)不能運(yùn)行,它提示需要一個(gè)Launch.json文件,OK,這是一個(gè)啟動(dòng)文件,我們來配置它。

{
    // 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那一行,僅需修改為自己編譯后產(chǎn)生的文件名,不如g++ -g 1.7.cpp -o build,所以這里我就取了build這個(gè)名字。

還有,就是要添加preLaunchTask這一行,名字與下面的task要對(duì)應(yīng)。

這里,它還需要一個(gè)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相對(duì)應(yīng),其他的就是命令行部分,完成這個(gè)文件后,我們ctrl+shift+b,這是會(huì)執(zhí)行task。

之后,我們打開main文件,設(shè)置斷點(diǎn),F(xiàn)5即可開始調(diào)試代碼。

關(guān)于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.但是,對(duì)于大多數(shù)調(diào)試方案,創(chuàng)建啟動(dòng)配置文件是有益的,因?yàn)樗试S您配置和保存調(diào)試設(shè)置詳細(xì)信息。 VS Code將配置信息保存在位于工作區(qū)(項(xiàng)目根文件夾)的.vscode文件夾或用戶設(shè)置或工作區(qū)設(shè)置中的launch.json文件中。

個(gè)人感覺可能是項(xiàng)目比較簡單所以看不來它的好處。


文章名稱:Ubuntu下VSCode如何調(diào)試C++代碼
分享路徑:http://m.5511xx.com/article/djhisio.html