|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
detecting if stream refers to standard input
I'm trying to detect if a stream is getting its stadnard input from the console (i.e. if it is waiting indefinitely for a user to type something) in a console application. Then, I can use this detection to generate some error. To achieve this, I used the following function istream myStream(cin); streamsize charsAvailable = myStream.rdbuf()->in_avail() if this call returns a result > 0, then there are characters available in the input buffer. unfortunately, if the result of this call is 0, one is not guaranteed that cin.get() will NOT have a char available Does anyone know a better solution (using the istream object ?) |
|
#2
|
|||
|
|||
|
Re: detecting if stream refers to standard input
Hi, What i feel that u want is to get the input from the Keyboard and wan't to manipulate the same. I hope the kbhit function can be used for the same easily. Sam. "Krist" <krist.blomme@ieee.org> wrote: > >I'm trying to detect if a stream is getting its stadnard input from the console >(i.e. if it is waiting indefinitely for a user to type something) in a console >application. Then, I can use this detection to generate some error. >To achieve this, I used the following function > >istream myStream(cin); > >streamsize charsAvailable = myStream.rdbuf()->in_avail() > >if this call returns a result > 0, then there are characters available in >the input buffer. >unfortunately, if the result of this call is 0, one is not guaranteed that >cin.get() will NOT have a char available > >Does anyone know a better solution (using the istream object ?) |
|
#3
|
|||
|
|||
|
Re: detecting if stream refers to standard input
"Sam" <devhelp@rediffmail.com> wrote: > >Hi, >What i feel that u want is to get the input from >the Keyboard and wan't to manipulate the same. >I hope the kbhit function can be used for the >same easily. > >Sam. In my program, input is read from a general stream. This stream can be standard input, a file or another stream. Normally the user doesn't want it to be standard input, because he doesn't want to type the input manually. So what I want is to detect if a general stream happens to be standard input from the console, so that I can inform the user that he propably doesn't want that. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|