I am trying to get the input like option from the user using cin but if the user is not responding for some time I want to use the default value which does not need users interaction can any one help to do this in unix c++?
int main()
{
char sex = 'M' ;
cout << "Are you Male/Female (M/F)?" << flush ;
cin >> setw(1) >> sex ; // Here I don't want to wait indefinatily
switch(sex)
{
case 'F' :
// do something
break ;
default :
case 'M' :
// do something
break ;
}
I am trying to get the input like option from the user using cin but if the user is not responding for some time I want to use the default value which does not need users interaction can any one help to do this in unix c++?
int main()
{
char sex = 'M' ;
cout << "Are you Male/Female (M/F)?" << flush ;
cin >> setw(1) >> sex ; // Here I don't want to wait indefinatily wait for
// some 20 seconds for the user input if he is not
// provided the input by that time use default
switch(sex)
{
case 'F' :
// do something
break ;
default :
case 'M' :
// do something
break ;
}