解决VS code 工具中C++运行黑窗口一闪而退的问题

1.通过在程序的最后一行加入system("pause");能解决一闪而退的问题。

2.每次写system("pause")麻烦,通过配置launch.json达到目的,分别配置program,将原来的删除,改为自己cmd路径,然后配置args参数,运行后没有闪退,也不需要加system("pause"),亲测有效。据说在这种情况下断点调试是没用的。下图为配置的代码

 

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "C:\\Windows\\System32\\cmd.exe",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "&",
                "echo.",
                "&",
                "pause"
            ],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\software\\MinGW\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "task g++"
        }
    ]
}

 

posted @ 2021-07-06 16:15  wancy  阅读(6744)  评论(4编辑  收藏  举报