Using Visual Studio and C++ how to prevent the debug screen from closing automatically?

Asked

Viewed 958 times

2

Using the code below I type the two numbers, but if I give enter after typing the second number the answer appears quickly and the debug closes.

int main(){

int num1, num2, answer;

cout << "Digite um número:";
cin >> num1;

cout << "Digite um número:";
cin >> num2;

answer = num1 * num2;
cout << "Resultado:" << answer << endl;

cin.get();
return 0;
}

I put

cin.get();

but it didn’t work.

I’m trying to use Ctrl+F5 to debug, but clicking F5 locks my cursor and I have to click again to unlock, why?

3 answers

3

You must insert a "break point" into the code, so the debugger will stop and you can view the information from the execution context.

Use the shortcut keys to execute step-by-step code. If your IDE is set to the Visual Studi 6 shortcut pattern (Tools->Options->Environment->Keyborad), for C++ projects, use :
F5 - runs to the stop point, if any;
F9 - insert stop point/remove stop point (break point) at the position where the courses are, or next valid position;
F10 - runs step-by-step;
F11 - enters the routine.

  • On which line do I insert "breakpoint". I entered after Return, tested before and the window continues to close. The IDE is set to "default/default".

  • And if I compiled the application, the breakpoint would still work for the user?

  • I switched to VS6, but the shortcuts don’t work if I press F5 my cursor hangs.

  • put the courses in the line "Answer = num1 * num2;", press F9 and then F5. The execution must stop there. The break only works in debugging. The version you will distribute should be compiled as a release.

1

After doing a search, I checked that I can prevent the debug screen from closing using:

 system("PAUSE");

0

is used

system("pause");

But to use this tool you have to add an extra library to

#include <stdlib.h>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.