start function

I am creating a game and want to get the user to press any key to start game how would I do that.

Simply include this code

1
2
char whateveryouwant
cin >> whateveryouwant;


If it doesn't work let me know please
Last edited on
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' );
That's a method that would work well but madmack76 said he wanted the user to press any key to start the game.
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.
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.
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.