键盘总是输入? [英] is cin always the keyboard's input?

查看:81
本文介绍了键盘总是输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主题中的问题。

标准是否对此有所说明,还是取决于平台?

任何有关建议的建议

/ B

解决方案

Bob Smith在主题中写道:

问题。
标准对此有所说明,还是平台依赖?
任何建议都很明确




的确,cin的全部意义在于这个细节对你隐藏。它

不仅取决于平台,还取决于案例。

例如,当您执行以下任何操作时:


猫文件| myapp

myapp<这些是指示系统使用该文件(更具体地说,

输入流)为cin。

第15.17节:
http:// www.parashift.com/c++-faq-lite/input-output.html


-

----- stephan beal

已注册的Linux用户#71917 http://counter.li.org

我自己说话,而不是我的雇主。内容可能会很热。小心地滑。阅读免责声明让你失明了。写它们更糟糕。你被警告了。


2003年10月15日星期三16:00:36 + 0300,Bob Smith< bo ****** @ jippii.fi>

写道:

主题中的问题。
标准是否说明了这一点,还是平台依赖?



平台相关。通常输入都是一个文件:


cat" file.txt" | myprog


上面将一个文件传输到myprog的标准输入中(在unix上至少
)。或者,cin可能是串行端口连接(在嵌入式设备上),或者是与大脑的心灵感应连接。它只是

基于标准流的程序输入。


Tom





stephan beal写道:

Bob Smith写道:

主题问题。
标准是否对此有所说明,还是平台依赖?
任何建议都很明确



的确,cin的重点是保持这个细节对你隐藏。它不仅取决于平台,而且取决于案例。
例如,当您执行以下任何操作时:

cat file | myapp
myapp<文件

这些是指示系统使用该文件(更具体地说,
输入流)为cin。

见15.17节:
http://www.parashift.com/c++- faq-lite / input-output.html



这里是我的问题:

m_reading是一个bool值,qDebug(... )是一个qt函数,qxevent是一个

类,可以从流中红色。

< snip>


if( !m_reading){

if(std :: cin.rdbuf() - > in_avail()){

m_reading = true;

qDebug(阅读......);

QxEvent e;

而(cin>> e){

m_event_queue .push(e);

counter ++;

}

qDebug(" ... read!");

m_reading = false;

} else {

qDebug(" .. no data");

}

}否则{

qDebug(已经阅读,返回来电者);

}

qDebug(" ready");

< / snip>


现在,尝试从一个程序输出数据到这个程序,比如

../testdatamaker|./eventlogger


(testdatamaker是一个为eventlogger编写testdata的程序)


testdatamaker每秒输出一个字符串,而eventlogger连续轮询

cin流,但它从不收到任何数据,它总是

返回没有数据。


所以我的应用程序的整个想法是它应该读取输入

stream,这是来自任何程序的任何输出,管道,并显示

数据。


我觉得很傻到问但是出了什么问题?* s *


任何帮助*非常感谢。

感谢'

/ B


question in subject.
does the standard say anything about this or is it platform dependent?
any advice much appeciated
/B

解决方案

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

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.


On Wed, 15 Oct 2003 16:00:36 +0300, Bob Smith <bo******@jippii.fi>
wrote:

question in subject.
does the standard say anything about this or is it platform dependent?



Platform dependent. Often input is a file anyway:

cat "file.txt" | myprog

The above pipes a file into the standard input of myprog (on unix at
least). Alternatively, cin might be a serial port connection (on an
embedded device), or a telepathic connection to your brain. It is just
the standard stream-based input to a program.

Tom




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


这篇关于键盘总是输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆