I don' know if it's called multitasking

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 ???
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 !
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;}
}
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 !
by other means I don't want to get input I want to check buffer my self
post your code, so i get an idea about the problem
Last edited on
By "freezez" you mean the program halts waiting for user input?
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!
yes I mean halts :D
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.
tnx alot ... I'll try the first ...... :D tnx
Topic archived. No new replies allowed.