如何在Visual Studio代码中完成后暂停控制台c ++应用程序

问题描述 投票:0回答:2

我想在完成后暂停控制台c ++程序以观察其结果。我找不到任何属性启动配置来暂停我的程序。这是我在launch.json中的代码。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) build and launch",
            "type": "cppvsdbg",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true
        }
    ]
}
c++ visual-studio-code
2个回答
1
投票

谢谢你的帮助。这是我的解决方案:我在命令中运行cmd来运行我的程序,并在完成后暂停

    {
        "name": "(Window) build and run",
        "type": "cppvsdbg",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "cmd",
        "args": [
            "/k", 
            "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "&",
            "pause",
            "&",
            "exit"
        ],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true
    }

0
投票

system("pause"); //这是我用的

cin.get(); //你可以使用它,但是当你按下ENTER键时,控制台会关闭,如果你输入一个变量它不是一个好的解决方案

© www.soinside.com 2019 - 2024. All rights reserved.