VS Code C++调试断点无效

问题遇到的现象和发生背景

使用vs code 进行c++调试无视断点直接运行到结尾

问题相关代码,请勿粘贴截图

demo.cpp:

#include <iostream>
using namespace std;

int main()
{
   cout << "Hello World!\n" ;
   cout << "Hello World!\n" ;
   cout << "Hello World!\n" ;
   cout << "Hello World!\n" ;
   cout << endl;
    return 0;
}

launch.json:

 { 
    "version": "0.2.0",
    "configurations": [
        {
            "name": "CPP",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "cmd",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "&",
                "pause"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "console": "externalTerminal",
            "preLaunchTask": "Compile"
        }
    ]
}

task.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-Wall",
                "-static-libgcc",
                "-fexec-charset=UTF-8"
            ],
            "type": "process",
            "group": "build",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            }
        },
        
    ]
}
运行结果及报错内容

img

img

img

我想要达到的结果

想使用断点调试

符号文件没了。建议添加一个 CMakeLists.txt 文件,让 CMake 来管理工程。可以点我头像看看