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?
This is a discussion on system pause within the C++ Programming forums, part of the General Programming Boards category; i need a way to simulate using the code system(pause); but without it saying "press any ket to continue . ...
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?
Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com
-the shroom has spoken
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
Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com
-the shroom has spoken
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
Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com
-the shroom has spoken
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?
Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com
-the shroom has spoken
> does main have to be void?
int main (void) or int main(int argc, char *argv[] is what you want...
-Govtcheez
govtcheez03@hotmail.com
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
Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com
-the shroom has spoken
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
Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com
-the shroom has spoken
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
Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com
-the shroom has spoken
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>
Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com
-the shroom has spoken