Hello,
I know that this is an old thread, but for me it’s new..
I faced this situation where the screen quit instantly, and I knew now that using system() and cin.ignore() aren’t good solutions
So, I used the pause(); function, and it goes ok unless there is a data input (cin>>xxx; ) even if I have to display a message after inputting the data
For example:

#include <iostream>
using namespace std;
#include <limits>
 
void pause() {
  std::cout << "Press ENTER to continue... ";
  std::cin.ignore( std::numeric_limits<streamsize>::max(), '\n' );
 
  }

int main() {
 
	int num1, num2;

	cout<<"Enter two numbers to calculate: \nnum1= ";
	cin>>num1;
	cout<<"\nnum2= ";
	cin>>num2;

	cout<<"\nI’ve got ur numbers!!";
	pause();
	return 0;
  }

Here, once I enter num2 and hit the Enter button, the “Press Enter to…” with the “I’ve got…” messages appears but the screen closes instantly when sometimes I couldn’t even see the messages because it’s too fast
However, when I remove all the cin(s), the screen shows me the cout(s) messages and waits for the key press to terminate!!
Could anyone give me an explanation for this situation??

What did SEARCH at the top of the page tell you when you tried to find your answer?

It shows me the pause() function which didn't work with me..

There is no pause() function.
I found this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.