[英]How to initialize stdout stdin with Qt 5.7
I noticed something with qDebug() QTextStrean and generally stdin, stdout wanna ask, how it works actually, see this: 我注意到qDebug()QTextStrean和通常的stdin,stdout想要询问其实际工作方式,请参见以下内容:
THIS WORKS! 这项工作!
method showmenu() using QTextStream 使用QTextStream的showmenu()方法
showMenu(){
QTextStream m_out(stdout);
QTextStream m_in(stdin);
m_out() << "Hey";
}
THIS DOESN'T WORK! 这不起作用!
.h 。H
//declaration
public:
QTextStream m_out;
QTextStream m_in;
.cpp .cpp
//method showMenu()
showMenu(){
m_out(stdout);
m_in(stdin);
m_out() << "Hey";
}
I noticed, it has problem with overloading, because also qDebug() uses stdout... am I correct? 我注意到,它在重载方面存在问题,因为qDebug()也使用stdout ...我正确吗?
It throws this error: 它引发此错误:
1>D:..\\App_console.cpp(20,15): error : no match for call to '(QTextStream) (_IO_FILE*&)' 1> D:.. \\ App_console.cpp(20,15):错误:无法匹配对'(QTextStream)(_IO_FILE *&)'的调用
I have included cstdio 我包括了cstdio
What could it be? 会是什么呢?
Pre C++11, You will need to do that in your Constructor Initialization List . 在C ++ 11之前的版本中,您需要在“ 构造函数初始化列表”中执行此操作 。 In the Constructor Definition of your class, say MyStreamer
, you can initialize it like this: 在类的构造器定义中,说MyStreamer
,您可以像这样初始化它:
class MyStreamer{
....
public:
QTextStream m_out;
QTextStream m_in;
};
In your .cpp file: 在您的.cpp文件中:
MyStreamer::MyStreamer(...) : m_out(stdout), m_in(stdin) {
....
}
In C++11 and beyond, you could simply use uniform initialization : 在C ++ 11及更高版本中,您可以简单地使用统一初始化 :
class MyStreamer{
....
public:
QTextStream m_out{stdout};
QTextStream m_in{stdin};
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.