Is it possible to use cin with Qt?

后端 未结 3 745
离开以前
离开以前 2020-12-06 11:50

Is it possible to use cin in Qt? I can use cout but cannot find examples of how to use cin within a Qt console application.

3条回答
  •  爱一瞬间的悲伤
    2020-12-06 12:09

    Yes, it's possible and works as expected although you can do things, like use threads, that may cause problems with this approach.

    However, I would recommend a more idiomatic (Qt) way to read from stdin:

    QString yourText;
    QFile file;
    file.open(stdin, QIODevice::ReadOnly);
    QTextStream qtin(&file);
    qtin >> yourText;
    

提交回复
热议问题