I don' know if it's called multitasking
MirMohammad (12)
Dec 7, 2012 at 8:39am UTC
I have a taxi-meter program in console.
Now in my main menu I want to get a choice from user (1,2,3 for example).
And at the time that the program is waiting for user input (with cin or something like that) what to refresh the menu for time changing! what should I do ???
MirMohammad (12)
Dec 7, 2012 at 9:18am UTC
I mean I don' wan my program to freeze until user press a key ! I want my program to bee in a loop until user press a key !
Darkmaster (331)
Dec 7, 2012 at 9:25am UTC
use a while loop check the users input in side that while loop and change the condotion of the while loop if the user enters a certain input
example:
1 2 3 4 5 6 7 8 9 10
bool run = true ;
std::string input;
while (run)
{
std::cin >> input;
if (input == "stop" )
{run=false ;}
}
MirMohammad (12)
Dec 7, 2012 at 9:48am UTC
Tnx for helping!
but the problem here is that in line cin my program freezez
I want it to be refreshed every 2 sec for example !
MirMohammad (12)
Dec 7, 2012 at 9:57am UTC
by other means I don't want to get input I want to check buffer my self
Darkmaster (331)
Dec 7, 2012 at 9:57am UTC
post your code, so i get an idea about the problem
Last edited on Dec 7, 2012 at 9:57am UTC
ajh32 (85)
Dec 7, 2012 at 9:58am UTC
By "freezez" you mean the program halts waiting for user input?
MirMohammad (12)
Dec 7, 2012 at 10:06am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
using namespace std;
#include <time.h>
const time_t ST=time(0);
int main()
{
char ch;
do
{
cout<<"Time passed : " <<(time(0)-ST)<<endl;
cin>>ch;
}while (ch!='0' );
return 0;
}
in this example I have a menu but after the program being launched the time is displayed 0 even if it take 5 min for user to enter a number ... I want this too refresh time until user enter a number!
rapidcoder (681)
Dec 7, 2012 at 11:57am UTC
There are two ways:
1. Use a separate thread that does the screen refreshing while the main thread is waiting for user input. Keyword: pthreads.
2. Use a library that allows you to create callbacks for key-presses or non-blocking key-testing. E.g. ncurses which has the getch() method.
MirMohammad (12)
Dec 7, 2012 at 12:02pm UTC
tnx alot ... I'll try the first ...... :D tnx