start function

Jun 3, 2013 at 6:15pm
I am creating a game and want to get the user to press any key to start game how would I do that.

Jun 3, 2013 at 6:31pm
Simply include this code

1
2
char whateveryouwant
cin >> whateveryouwant;


If it doesn't work let me know please
Last edited on Jun 3, 2013 at 6:32pm
Jun 3, 2013 at 6:54pm
closed account (3qX21hU5)
Just incase the user enters something more then just pressing enter you might want to do something like this.

1
2
std::cout << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
Jun 3, 2013 at 6:56pm
That's a method that would work well but madmack76 said he wanted the user to press any key to start the game.
Jun 3, 2013 at 7:14pm
closed account (3qX21hU5)
That's a method that would work well but madmack76 said he wanted the user to press any key to start the game.


Well the example I put up was the exact same as yours expect it can take up to a unlimited number of characters

But anyways unless he wants to get into more advanced libraries like Curses or win32 programming he will have to press enter to continue... So might as well make it easy and just tell the user to press enter to continue instead of any key.
Jun 3, 2013 at 7:47pm
Why not simply add system("PAUSE")?
I know it's bad, and i don't really use it but it will work as he wants.
Jun 3, 2013 at 7:52pm
closed account (3qX21hU5)
Do not use system('PAUSE') because it isn't portable and it is a very huge gaping security hole. Best get into the practice of not using it while you are first learning.
Topic archived. No new replies allowed.