Re: is cin always the keyboard's input?

From: Bob Smith (bobsmith_at_jippii.fi)
Date: 10/15/03


Date: Wed, 15 Oct 2003 16:18:53 +0300


stephan beal wrote:

> Bob Smith wrote:
>
>
>>question in subject.
>>does the standard say anything about this or is it platform dependent?
>>any advice much appeciated
>>
>
> Indeed, the whole point of 'cin' is to keep this detail hidden from you. It
> is not only platform-dependent, but case-dependent.
> e.g., when you do any of the following:
>
> cat file | myapp
> myapp < file
>
> these are instructing the system to use the file (more specifically, the
> input stream) as cin.
>
>
> See section 15.17 in:
> http://www.parashift.com/c++-faq-lite/input-output.html

well here is my problem:
m_reading is a bool value, qDebug(...) is a qt function, qxevent is a
class which can red from streams.
<snip>

   if ( !m_reading ){
     if ( std::cin.rdbuf()->in_avail() ){
       m_reading = true;
       qDebug( "reading...");
       QxEvent e;
       while( cin >> e ) {
       m_event_queue.push( e );
       counter++;
       }
       qDebug( "...read!");
       m_reading = false;
     }else{
       qDebug("..no data" );
     }
   }else{
     qDebug("already reading, return to caller");
   }
   qDebug("ready");
</snip>

Now, trying to output data from one program, to this program, like
./testdatamaker|./eventlogger

( testdatamaker is a program for making up testdata for eventlogger )

testdatamaker outputs strings every second, and eventlogger polls the
cin stream continuously, but it never receives any data, it always
returns with "no data".

So the whole idea with my application is that it should read the input
stream, that being any output from any program, piped, and make display
data out of it.

I feel silly to ask but what is going wrong ?*s*

any help *very* much appreciated.
thank's
/B



Relevant Pages

  • Re: std::cin.ignore() and std::cin.clear()
    ... So what does cleardo anyway, if not clear all cin data? ... It clears the error state of the stream. ... The extracts an unlimited amount of characters (the max is a sentinel ... C++ FAQ: http://www.parashift.com/c++-faq-lite/ ...
    (comp.lang.cpp)
  • Re: is cin always the keyboards input?
    ... the whole point of 'cin' is to keep this detail hidden from you. ... >> cat file | myapp ... Set stdin to non-blocking mode ... Here the stream will be in an error state. ...
    (comp.lang.cpp)
  • Re: cin error recovery
    ... cin>> i1; ... > When stream input encounters an illegal character, ... > have to be on separate lines. ...
    (comp.lang.cpp)
  • Re: Wierd newbie problem
    ... You should flush cout before reading from cin. ... endl writes a newline and flushes the stream. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Wierd newbie problem
    ... > You should flush cout before reading from cin. ... > it's possible for the text to not actually display ... > endl writes a newline and flushes the stream. ...
    (alt.comp.lang.learn.c-cpp)