【问题标题】:C++/QT: QTextStream program crashesC++/QT:QTextStream 程序崩溃
【发布时间】:2014-10-28 20:46:14
【问题描述】:

我知道了:

#include <QApplication>
#include <iostream>
#include <QString>
#include <QTextStream>
using namespace std;

int main(int argc, char**argv)
{
    QTextStream qt_in(stdin);
    QTextStream qt_out(stdout);
    QString line;

    qtout >> "give input";   // -> deprecated conversion from string constant to 'char*'
    do {
         line = qt_in.readLine();
    } while(!line.isNull());

qt_out <<input;
}

当我想启动程序时,它会立即崩溃。 我正在使用 QT-Creator,Compilerkit:“Desktop QT 5.3 MinGW 32Bit”。

有人有想法吗?语法应该是正确的,编译器不会引发错误,除了我作为注释写的那个。

编辑: Win7 Pro 64Bit,最新版本。

【问题讨论】:

  • qtin:readLine(); - 是错字吗?你的程序编译了吗?
  • 抱歉,是的,这是一个错字,仅在 stackoverflow 中。手工输入,而不是从真实代码中复制。
  • 所以你有一个冒号?线是什么意思qt_out &lt;&lt;input;?请确保您发布的代码可以编译。
  • the syntac should be correct, and the compiler doesn't raise errors -> 由于 c++ 语法 nazi 确实抱怨,此代码无法构建。正如@AntonSavin 所提到的,从输出中读取(有错字)并不是它应该的样子

标签: c++ qt stream crash


【解决方案1】:

通过这条线

qtout >> "give input"; 

您正在阅读输出(不再提及名称中的错字),因此将其更改为

qt_out << "give input"; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-02
    • 2012-04-16
    相关资源
    最近更新 更多