HOW do i press any key to continue??????

Started by
21 comments, last by graveyard filla 20 years, 2 months ago
high, i have a simple text RPG game and when the player kills someone, i want it to say "press any key to continue" and then execute then next line of code ive actually come up with this problem a lot and cant seem to fix it. the best way i came up with to do this is char holder; cout>>"Press any key then press enter to continue">>endl; cin << holder; but this forces the user to press a key THEN enter to continue the game. i also thought about using getline, considering it has a terminating argument IE when you press that key it will end therfore doing string holder; cout>>"Press enter twice to continue">>endl; getline (cin,holder,'/n') but that caused a whole load of problems throughout my whole game (i think it has something to do with cin.ignore() but i just would rather not mess with getline at all. anyway, so how do i do it? the problem is i have a bunch of clearscreens inside my game, so some stuff gets wiped out before you can see it, so my idea was to add a "press any key to continue" before i cleared the screen, so you could see what you were suposed to see. now that i think about it, isnt there a sleep() function that will wait an x amount of seconds before it goes to the next line of code? what is the sytax for that, and what headers to i include? maybe ill just make it delay instead, it seems to make more sence, although id still like an answer to my first question because i come up with that problem a lot. thanks for any help.... [edited by - graveyard filla on January 25, 2004 3:49:41 PM] [edited by - graveyard filla on January 25, 2004 3:50:33 PM]
FTA, my 2D futuristic action MMORPG
Advertisement
use getch();

It reads in a single character from the command line and doesn''t display it.

Use getche() if you want the character to be displayed.
thanks, and what library? cant seem to get it to work with any of the ones im including...

ps i figured out the sleep() problem.
FTA, my 2D futuristic action MMORPG
getch() is in conio.h
You want to include conio.h

tj963
tj963
And your other question about delaying, you can use Sleep(ms); let say if you want to delay 5 seconds you would use Sleep(5000); etc.

You might need to include windows.h for this btw.




--{You fight like a dairy farmer!}

--{You fight like a dairy farmer!}

isn''t there a system call as well? One the even displays the "Press any key to continue..." line?

system("PAUSE");

don''t remember which include it needs but it''s bound to be one of these:
#include <iostream>
#include <conio.h>
#include <cstdlib>
You could also use cin.get();
or
cout << "Press any key to continue";
while(!kbhit()) ;
Another one bites the dust.
quote:Original post by kVandaele
isn''t there a system call as well? One the even displays the "Press any key to continue..." line?

system("PAUSE");


That''s really really bad. What is does is start a second process, command or cmd, and execute one batch command, pause, then the command processor exits again. Because it has to be able to execute old dos programs it allocates 640K plus the whole dos interface.
System() is for the very lazy, a decent programmer should solve it the correct way.

This topic is closed to new replies.

Advertisement