• 7608阅读
  • 5回复

怎么读取文件中的某一行??? [复制链接]

上一主题 下一主题
离线ww18031901
 

只看楼主 正序阅读 楼主  发表于: 2008-12-15
— 本帖被 XChinux 执行加亮操作(2009-01-03) —
关键词: 读取某一行
怎么才能 读取文件中 指定的行?



离线ww18031901

只看该作者 5楼 发表于: 2008-12-30
哈哈哈

谢谢


我 也是 for下去的
离线lj_0212

只看该作者 4楼 发表于: 2008-12-17
离线guoyun_he

只看该作者 3楼 发表于: 2008-12-17
QT的QFile没有提供定位到具体那一行的函数,只是提供了seek函数。

qint64 QIODevice::readLine ( char * data, qint64 maxSize )
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes, stores the characters in data, and returns the number of bytes read. If a line could not be read but no error ocurred, this function returns 0. If an error occurs, this function returns what it could the length of what could be read, or -1 if nothing was read.
A terminating '\0' byte is always appended to data, so maxSize must be larger than 1.
Data is read until either of the following conditions are met:
The first '\n' character is read.
maxSize - 1 bytes are read.
The end of the device data is detected.
For example, the following code reads a line of characters from a file:
        QFile file("box.txt");
        if (file.open(QFile::ReadOnly)) {
            char buf[1024];
            qint64 lineLength = file.readLine(buf, sizeof(buf));
            if (lineLength != -1) {
                // the line is available in buf
            }
        }
The newline character ('\n') is included in the buffer. If a newline is not encountered before maxSize - 1 bytes are read, a newline will not be inserted into the buffer. On windows newline characters are replaced with '\n'.
This function calls readLineData(), which is implemented using repeated calls to getChar(). You can provide a more efficient implementation by reimplementing readLineData() in your own subclass.
See also getChar(), read(), and write().
离线ww18031901

只看该作者 2楼 发表于: 2008-12-17
假如我只要读第五行 怎么带参数??
离线stdjgwyc
只看该作者 1楼 发表于: 2008-12-15
QFile的readLine()
QT交流群群号:2906359,(200人大群,持续升级)
快速回复
限100 字节
 
上一个 下一个