C/C++ black screen opens and closes

While executing a program in C++, it happens the black screen opens and closes automatically without displaying the output(program is correct). How to recover from this situation?

Showing Answers 1 - 18 of 18 Answers

Sugan

  • Sep 26th, 2011
 

Yeah .. Surendra is right..

This happens when getch() or getche() is not given at the end.

getch will let the output to be displayed till the user enters a character.
As soon as the user enters a character it transfers the control back to the main function.
Then it continues executing the rest of the lines.



  Was this answer useful?  Yes

jobin

  • Oct 4th, 2011
 

getch();

  Was this answer useful?  Yes

sebius

  • Aug 25th, 2013
 

Try this

Code
  1. system("pause");

  Was this answer useful?  Yes

Amit

  • Jun 27th, 2014
 

use getchar() before return in the main.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions