Feb 13, 2016 at 6:16pm UTC
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 Feb 13, 2016 at 6:24pm UTC
Feb 13, 2016 at 6:23pm UTC
Probably because you didn't use the using namespace std;
clause and you need to properly scope this item std::flush
.
Last edited on Feb 13, 2016 at 6:24pm UTC
Feb 13, 2016 at 6:26pm UTC
your method is not bad, its actually pretty good, the console closing down depends on what compiler are you using
Feb 13, 2016 at 6:29pm UTC
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 Feb 13, 2016 at 6:29pm UTC
Feb 13, 2016 at 6:31pm UTC
Perhaps you need to add a cin.get()
after the ignore statement?
Feb 13, 2016 at 6:37pm UTC
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");
Feb 13, 2016 at 6:45pm UTC
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