问题描述
我想逐行读取文件(.txt)但不要在while循环中读取(一旦读取整个文件)。目前我正在整理文件一次。但是我想要做的是读取一行而不是回到正常的MAIN函数,而不是稍后调用
I want to read the file(.txt) line by line but not in while loop(once reading whole fle). Currently I am reading the file once as whole. BUT what I want to do is to read one line than go back to normal MAIN function than later on call
ReadDumpFile
并读取下一行。任何帮助将不胜感激
注意:: .txt文件中的行大小不同
示例
and read the next line. Any help would be appreciated
NOTE:: Lines in .txt file are not same in size
Example
5:50:12:560:434, Rx, 7, 0x1E3, 00 80 2B 00 77 00 7D
5:50:12:560:615, Ax, 4, 0x760, 00 12 84 41
5:50:12:560:826, gc, 5, 0x2f1, 64 5A 43 20 4E
READ文件功能
READ File function
readingLogFile(){
QString LFileName = "P_1.trc";
QFile logfile(LFileName );
QTextStream in(&logfile);
while (!in.atEnd())
{
QString fileLine = in.readLine(); //
if(fileLine.trimmed().isEmpty()!=true)
{
qDebug()<<fileLine;
}
}
}
什么我试过了:
我认为我需要做的是将前一行保留在指针中。并且净时间先前为+ 1。但不知道如何阅读文档中的特定行。如果.txt文件包含1000000行。我怎么读行#670000 ???
What I have tried:
What i think i need to do is to keep previous line in pointer. And net time previous+1. but dont know how to read a specific line inside the document. if .txt file contain 1000000 line. how i can read line#670000 ???
推荐答案
- 以大块的形式读取文件并跳过内存中不需要的行。
这篇关于逐行读取txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!