QFile file("data.asc");
file.open(QIODevice::readOnly);

while (!file.atEnd()) {
    QByteArray allData = file.readLine();

    unsigned long data = 0;
    QTextStream out(&allData);

    while (!out.atEnd()) {
        out >> data;
        qDebug() << data;
    }
}

先把文件中所有的数据读取出来,存放到QBytesArray类型的数组中,使用QTextStream的方式读取

例如txt中

Qt读取自定义文件类型中的整数(unsigned long)

读取出来是这样的:

Qt读取自定义文件类型中的整数(unsigned long)

 

如果文件的末尾多个空格的话,为输出一个 0 

不知道怎么解决这个问题(知道的话或者有更好的方法思路,分享一下,谢谢)

相关文章:

  • 2021-12-25
  • 2021-08-04
  • 2021-06-28
  • 2021-11-03
  • 2022-01-07
  • 2021-04-13
  • 2021-11-25
  • 2022-12-23
猜你喜欢
  • 2021-08-24
  • 2022-01-01
  • 2021-08-26
  • 2022-02-08
  • 2022-01-03
相关资源
相似解决方案