Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Zidane

A pretty simple question, but i just cant... :P

This topic is 5598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is a pretty simple problem really: How would one pause at the console waiting for any key to be pressed before going on i.e.: DoStuff(); printf("Press anykey to continue...\n"); while(){} DoMoreStuff(); (Using the std library) I know this a very simple problem, but I have a had a long day and red bull doesnt seem to work anymore

Share this post


Link to post
Share on other sites
Advertisement
you could:

#include <conio.h>
do
{
cout << "Press any key to continue...";
}
while (!(kbhit());

I think thats how you would use it. using a do...while loop would ensure the message being displayed at least once, or you could just do a while loop and display the message before you execute the loop.

kbhit() returns TRUE if any key has been pressed and FALSE otherwise.

[edited by - deathtrap on March 25, 2003 12:04:49 PM]

[edited by - deathtrap on March 25, 2003 12:05:07 PM]

[edited by - deathtrap on March 25, 2003 12:05:35 PM]

Share this post


Link to post
Share on other sites
That would display the string a bazillion times until you press a key. The output needs to happen before the loop.

Share this post


Link to post
Share on other sites
  
#include <cstdlib> //at top of program

system("pause); //wherever you want to wait



That just executes the DOS 'pause' command, which does exactly what you are trying to do.



"It's better to burn out than fade away"
--Neil Young

[edited by - ze_jackal on March 25, 2003 12:12:36 PM]

Share this post


Link to post
Share on other sites
could just make an empty do...while loop couldn't you so nothing would be displayed, or is there a more efficient method?

[edit:ze_jackal posted before so my comment is pretty much invalidated ]

[edited by - deathtrap on March 25, 2003 12:14:19 PM]

Share this post


Link to post
Share on other sites
To the guy who said it was system("pause);

it''s actually

system("PAUSE");

(you forgot a " in there )



DigiCode - My solo company in the process

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!