简体   繁体   English

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

[英]How to pause a console c++ application when it finished in Visual studio code

I want to pause the console c++ program after it finished to watch its result.我想在完成后暂停控制台 C++ 程序以查看其结果。 I can't find any attribute launch configuration to pause my program.我找不到任何属性启动配置来暂停我的程序。 Here is my code in launch.json.这是我在 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
        }
    ]
}

thanks for your help.谢谢你的帮助。 here's my solution: i run a cmd within the command to run my program and pause when its done这是我的解决方案:我在命令中运行一个 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
    }

Put a breakpoint at the end of main() :main()的末尾放置一个断点:

Then run under debugger ( F5 ).然后在调试器 ( F5 ) 下运行。 It'll stop just before program exit.它会在程序退出前停止。

system("pause"); //this is what I use //这是我用的

cin.get(); //you can use this, but when you press ENTER, the console closes, if you enter a variable it is not a good solution //你可以使用这个,但是当你按下 ENTER 时,控制台关闭,如果你输入一个变量,这不是一个好的解决方案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++:如何使用Windows Media Player在Visual Studio控制台应用程序中播放和暂停mp3文件? - C++:How to use windows media player to play and pause mp3 file in a visual studio console application program? Visual Studio C ++ 2010如何将ICON添加到控制台应用程序 - Visual Studio C++ 2010 How to add an ICON to a console application 为什么在Visual Studio中用c ++编写GUI应用程序的代码与控制台应用程序不同? - Why the code to write GUI application in c++ in Visual Studio is different than to console application? 在Visual Studio中使用freopen()时,c ++系统(“暂停”)不起作用 - when using freopen() in visual studio c++ system(“pause”) is not working 如何在 Visual Studio Code 中构建和运行 c++ 应用程序作为发布版 - How to build and run a c++ application as release in Visual Studio Code Visual Studio C ++控制台应用程序无法运行 - Visual Studio C++ Console Application Won't Run 在Visual Studio 2012中对C ++控制台应用程序进行单元测试 - Unit testing c++ console application in Visual Studio 2012 Visual Studio 2022 for mac 无法创建 c++ 控制台应用程序 - visual studio 2022 for mac cannot create c++ console application 无法在Visual Studio 2013中创建C ++控制台应用程序 - Can't create C++ console application in Visual Studio 2013 C ++-Qt-Visual Studio 2010-具有GUI和控制台的应用程序 - C++ - Qt - Visual Studio 2010 - application with both gui and console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM