How can I read only first word in every line in a text file while using QFile in Qt? Thanks.

有帮助吗?

解决方案

use

    QFile ifile("in.txt");
    QString text = txStream.readLine();
    QStringList splitline = text.split(" ");
    QFile ofile("out.txt");
    ofile.open(QIODevice::WriteOnly | QIODevice::Text);

     QTextStream out(&ofile);

     // join QStringList by "\n" to write each single word in an own line
     out << splitline.join("\n");

     ofile.close(); 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top