i need a way to simulate using the code system(pause); but without it saying "press any ket to continue . . ." how can i do this?
i need a way to simulate using the code system(pause); but without it saying "press any ket to continue . . ." how can i do this?
There are several ways to do it. You could use a for loop, but it would be processor dependant. You could also write your own time function for your pause. It would then pause for however many seconds you wanted on any system. Include the time.h & clock( ) & you'll need to do something like( example only for understanding )...
-foxCode:void timeout( int seconds ) { clock_t endtime = clock( ) + seconds * CLOCKS_PER_SEC; while( clock( ) < endtime ); }
i have no clue wut that meant. im sorta a newb
How long do you want your pause to be? Post a little code so we can see what you're trying to do & we'll help you. It will most likely not be me though as I need to run for now.
-fox
untill the user presses enter
Here you go, this code snippet will wait until the user presses 'ENTER' (char 32) to continue:
Code:#include<iostream> #include <conio.h> using namespace std; int main(void){ char keycode; int keypress = 1; while(keypress){ if(kbhit()){ keycode = getch(); if ((keycode = (char)13)) keypress = 0; } } return(0); }
Last edited by Traveller; 07-17-2002 at 04:00 AM.
does main have to be void?
> does main have to be void?
int main (void) or int main(int argc, char *argv[] is what you want...
-Govtcheez
[email protected]
adn do i put the code after the snipet u gave me not including the header and stuff. or like INSIDE it if oy know what i mean
meaning
like that\?Code:// some previous program here char keycode; int keypress = 1; while(keypress){ if(kbhit()){ keycode = getch(); if ((keycode = (char)13)) keypress = 0; } } //rest of the program here
Just think things through. You use this where you want your pause. The code that Traveller gave you will wait for the "Enter keypress". So in your program you are doing, think about where you want the program to wait for "Enter keypress" and use this part of Traveller's code and it will work fine there.Code://Traveller's code while(keypress){ if(kbhit()){ keycode = getch(); if ((keycode = (char)13)) keypress = 0; } }
-fox
oops, I did not log in my last post.
-fox
it syas kbhit cannot be used as a function
kbhit() is a function. What compiler and what include files do you have?
look in my signiture, have u noticed everyone puts their compiler in their sig! as for the header file0s..
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <fstream>