is this ok for keeping console open

I call this function at the end of main for not closing the console by simply pressing enter.
i have tried various methods as i found in this thread: http://www.cplusplus.com/articles/iw6AC542/


and for some reason this just doesn't work for me
1
2
3
4
5
void PressEnterToContinue()
  {
  std::cout << "Press ENTER to continue... " << flush;
  std::cin.ignore( std::numeric_limits <std::streamsize> ::max(), '\n' );
  }


it gives me: error C2065: 'flush' : undeclared identifier
how, what, why?

but this is how i managed to get it to work
How ok is this?

1
2
3
4
5
6
7
8
9
10
inline void keep_window_open(){ 
char c; 
std::cout << "Insert any key to close!\n"; 
std::cin >> c; 
}

main()

keep_window_open();
return 0;
Last edited on
Probably because you didn't use the using namespace std; clause and you need to properly scope this item std::flush.
Last edited on
your method is not bad, its actually pretty good, the console closing down depends on what compiler are you using
i use microsoft visual studio express 2013

i added std::flush but now the console closes as if i don't have that bit of code at all
Last edited on
Perhaps you need to add a cin.get() after the ignore statement?
you can start the application with CTRL + F5 or either you can use a std::cin or something . it doesnt really matter, just dont use system("pause");
so i got it to work after adding cin.get(); after cin.ignore

thank you for your support

now i have 2 methods to keep the console window open, i just need to decide on which to use
Topic archived. No new replies allowed.