Launch.json vscode C++

Mở thư mục trong Visual Studio Code và viết chương trình C++

  1. Đóng Visual Studio Code nếu nó hiện đang mở. Sau đó khởi chạy Visual Studio Code. Chọn Tệp -> Mở Thư mục…
  2. Tạo một thư mục hoàn toàn mới tại bất kỳ vị trí nào bạn chọn. Trong ví dụ này, thư mục mới sẽ được gọi là mã hóa.
    Launch.json vscode C++
  3. Trong trình chỉnh sửa Mã VS chính, nhấp vào Tệp -> Tệp mới, sau đó nhấn Ctrl + S để lưu dưới dạng “mã. cpp”
    Launch.json vscode C++
  4. Cài đặt tiện ích mở rộng C++ cho Mã VS

Đặt trình biên dịchPath

  1. Nhấn Ctrl+Shift+P, bắt đầu nhập “C/C++” rồi chọn Chỉnh sửa cấu hình (JSON) từ danh sách đề xuất. Mã VS tạo một tệp có tên c_cpp_properties. json và điền vào đó các cài đặt mặc định.
    Launch.json vscode C++
  2. Tìm cài đặt
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    9 và dán vào tên đường dẫn đầy đủ của g++. exe trong thư mục bin Mingw-w64 mà bạn vừa thêm vào biến Đường dẫn. (
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    0, lưu ý cách bạn phải thực hiện gấp đôi “
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    1” do quy ước json)
  3. Đặt
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    2 thành
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    3
    Launch.json vscode C++
  4. Tệp
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    4 của bạn sẽ trông như thế này
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "C:\\Mingw-w64\\mingw32\\bin\\g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

Tạo một nhiệm vụ xây dựng

  1. Tiếp theo, nhấn Ctrl + Shift + P lần nữa và bắt đầu nhập "tác vụ" và chọn Nhiệm vụ. Định cấu hình Tác vụ xây dựng mặc định từ danh sách đề xuất, sau đó chọn Tạo tác vụ. tệp json từ mẫu. Sau đó chọn MSBuild. Mã VS tạo một tác vụ mặc định. tệp json trong trình chỉnh sửa
  2. Tìm cài đặt
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    0 và thay đổi nó thành
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    1
  3. Thay đổi cài đặt
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    2 thành
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    3
    Launch.json vscode C++
  4. {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    4 của bạn sẽ trông như thế này
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": ["-g", "-o", "a.exe", "code.cpp"],
            "group": "build",
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": "$msCompile"
        }
    ]
}

Định cấu hình cài đặt gỡ lỗi

Tiếp theo, chúng tôi sẽ định cấu hình Mã VS để nó khởi chạy trình gỡ lỗi gdb đúng cách
  1. Nhấp vào Gỡ lỗi -> Mở Cấu hình rồi chọn C++ (GDB/LLDB) từ danh sách đề xuất. Mã VS tạo khởi chạy mặc định. tệp json trong trình chỉnh sửa.
    Launch.json vscode C++
  2. Tìm cài đặt
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    5 và xóa mọi thứ trừ phần cuối cùng
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    6
  3. Tìm
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    7 và trỏ nó vào tệp gdb trong thư mục bin Mingw-w64 của bạn, tôi. e.
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    8
    Launch.json vscode C++
  4. Tệp
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    9 hoàn chỉnh của bạn sẽ trông như thế này
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": ["-g", "-o", "a.exe", "code.cpp"],
            "group": "build",
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": "$msCompile"
        }
    ]
}
2

Đặt điểm dừng và gỡ lỗi

  1. đi đến mã. cpp trong trình chỉnh sửa, hãy viết chương trình C++ của bạn và nhấn Ctrl+Shift+B rồi Enter để biên dịch
  2. Sau đó đặt điểm dừng và nhấn F5 để gỡ lỗi

Cài đặt tiền thưởng bổ sung

  1. Sau bất kỳ thay đổi nào đối với mã nguồn, hãy luôn nhớ Ctrl+Shift+B để xây dựng trước khi bạn chạy gỡ lỗi. Nếu bạn muốn F5 luôn để xây dựng lại mã theo mặc định, hãy chèn phần này ngay bên dưới dòng cài đặt
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    5 trong tệp
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    9.
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    5
  2. Lý tưởng nhất là bạn muốn đầu ra gỡ lỗi nằm trên một bảng điều khiển riêng. Trong
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    9, tìm cài đặt
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    23 và thay đổi nó thành
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": ["-g", "-o", "a.exe", "code.cpp"],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    
    24

Khởi chạy json ở đâu trong Mã VS?

Ra mắt. json nằm ở trong một. thư mục vscode trong không gian làm việc của bạn (thư mục gốc của dự án) .

Khởi chạy json trong Mã VS là gì?

Ra mắt. json được dùng để định cấu hình trình gỡ lỗi trong Visual Studio Code . Visual Studio Code tạo ra một lần khởi chạy. json (dưới một. vscode trong dự án của bạn) với hầu hết tất cả các thông tin cần thiết.