0

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??

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by WaltP
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.