keep_window_open() doesn't work

Hi,

In below code the keep_window_open() in the catch function doesn't work, that is, it keeps the windows in try block but not in catch block. Why?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "std_lib_facilities.h"
using namespace std;

int main()
 try 
{
  int h;
  cin >> h;
  if(cin) cout << "OK ";
  else error("NOT AN INTEGER ");
  keep_window_open();
  return 0;
}

catch(exception& e) {
	cerr<<e.what();
	keep_window_open();
	return 1;
}
Last edited on
Execute your console programs from a console.

The least you could do is to provide the definitions of those functions that are giving you issues.
Last edited on
after cin >> h failed, it indicated that by setting the std::ios_base::failbit on std::cin. While it is set, I/O functions return immediately, including the input function called from within keep_window_open()

As with any unprocessed input, you need to call cin.clear() to remove the failbit, and then process the input (read it into a string, or ignore with an appropriate cin.ignore)

Topic archived. No new replies allowed.