Is it possible to use cin with Qt?

后端 未结 3 743
离开以前
离开以前 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:08

    I tested out Kaleb Pederson's answer, and found a more consise way than the solution he presented (though I have to thank him for pointing me to the right direction):

    QTextStream qtin(stdin); 
    QString line = qtin.readLine();  // This is how you read the entire line
    
    QString word;
    qtin >> word;    // This is how you read a word (separated by space) at a time.
    

    In other words, you don't really need QFile as your middleman.

提交回复
热议问题