|
-
April 30th, 2003, 12:01 AM
#1
small doubt about cin>>
Hi ,
We know that when we want to get input from console most frequently used one is cin and it waits infinitely for input.
But I want to use cin to get input without waiting more than specified time.That time may be some thing like after 5 sec.
Is it possible or not?
If so, can any one tell me the way to do it?
with regards...
seshu
Last edited by seshreddy; April 30th, 2003 at 12:04 AM.
make it possible
-
April 30th, 2003, 03:51 AM
#2
Nope! there is no time specific input readers.
Muthu
-
April 30th, 2003, 04:38 AM
#3
how it will be if u use operator overloading?
but what happens when we want to infinitely for the input in some conditions of the application.
please think abnout it..
with regards...
seshu
make it possible
-
April 30th, 2003, 07:37 PM
#4
Sesh,
I am not really sure how overloading will be effective in this matter. A possible workaround could be running a separate thread with our regular cin to wait for the input. The parent process can do a Waitforsingleobject(handle,SPECIFIEDTIME);
If the input has been entered, return and come out. Otherwise kill the thread.
I am not really sure abt the overloading idea u r trying to say.
Muthu
-
April 30th, 2003, 08:40 PM
#5
Would a cout be read by cin? Maybe you test this:
Code:
#include <iostream>
#include <string>
using namespace std;
void cin_timeout( void* pVoid )
{
long timeout = pVoid;
Sleep( timeout );
cout << "timeout";
}
int main()
{
string s;
_beginthread( cin_timeout, 0, 5 );
cin >> s;
return 0;
}
-
May 1st, 2003, 08:37 AM
#6
Hi,
thank u all.
i tried to run the program using thread but i am getting error C2065: '_beginthread' : undeclared identifier
this is vc++ compiler and windows 2000.
this is the code that our friend has given abd which i too tried.
#include <iostream>
#include <string>
#include <windows.h>
#include <process.h>
using namespace std;
void cin_timeout( void* pVoid )
{
long timeout = (long)pVoid;
Sleep( timeout );
cout << "timeout";
}
int main()
{
string s;
_beginthread( cin_timeout, 0, 5 );
cin >> s;
return 0;
}
bye
seshu
make it possible
-
May 1st, 2003, 11:52 AM
#7
You need to compile with /MT, but I just tried and it doesn't work
-
May 2nd, 2003, 01:27 AM
#8
you may get rid of the error with proper settings. i feel.
If you try your code in a MFC supported console application will do the work.
start a console project but in the next step select "an application that supports MFC" this will start a console application with tmain()
then you can do the work.
this is may work as a solution for your error.
and don't forget to add #include<process.h>
it solves the problem of the compiler error
cheers
mahanare
Last edited by mahanare; May 2nd, 2003 at 01:31 AM.
Thanks n Regards
Harinath Reddy
Learn Hello World Program
A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible. There are no prima donnas in engineering. - Freeman Dyson
-
May 2nd, 2003, 05:31 AM
#9
hello
how can we do it with mfc support console application?
i tried to do but again same error is coming...
look at this..
bye
seshu
make it possible
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|