[英]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.