Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > C++

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 03-28-2001, 05:55 AM
Krist
Guest
 
Posts: n/a
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 ?)
Reply With Quote
  #2  
Old 03-28-2001, 06:16 AM
Sam
Guest
 
Posts: n/a
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 ?)


Reply With Quote
  #3  
Old 03-28-2001, 07:26 AM
Krist
Guest
 
Posts: n/a
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.


Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 01:04 AM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.