1: //test_pause2.cpp
2: //A test driver for the Scobey::Pause() free function.
3: //Illustrates why the Pause() function needs to have the
4: //standard input stream empty before it is called.
6: #include <iostream>
7: using namespace std;
9: #include "utilities.h"
10: using Scobey::Pause;
12: int main()
13: {
14: Pause(0, "\nTesting the Scobey::Pause() free function ..."
15: "\n\nThis program shows that the pre-condition for "
16: "the Pause() function (an empty\ninput stream) is necessary "
17: "(critical, in fact) if calling the function is\nindeed to "
18: "cause the program to pause.");
20: Pause(0, "We do this by reading in two integers, clearing the input "
21: "stream after the\nfirst one is read but not after the second. "
22: "We also call the Pause() function\nafter reading each integer. "
23: "But, note that the although the program pauses\nafter reading the "
24: "first integer, it does not pause after reading the second. "
25: "\nThe reason is that after reading the first integer, but not "
26: "after reading\nthe second, we cleared the input stream with "
27: "a call to cin.ignore().");
29: int i1;
30: cout << "Enter an integer: ";
31: cin >> i1; cin.ignore(80, '\n');
32: Pause();
34: int i2;
35: cout << "Enter another integer: ";
36: cin >> i2; //Should have cin.ignore(80, '\n'); here too!
37: Pause();
39: cout << "\nHere are the two integers: "
40: << i1 << " " << i2 << "\n\n";
42: Pause(0, "No more tests to perform."
43: "\nProgram will now terminate.");
44: }