Reputation: 71
I want to pause the console c++ program after it finished to watch its result. I can't find any attribute launch configuration to pause my program. Here is my code in 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
}
]
}
Upvotes: 3
Views: 3206
Reputation: 85531
Put a breakpoint at the end of main()
:
Then run under debugger (F5). It'll stop just before program exit.
Upvotes: 1
Reputation: 71
thanks for your help. here's my solution: i run a cmd within the command to run my program and pause when its done
{
"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
}
Upvotes: 4
Reputation: 1
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
Upvotes: 0