我正在尝试使用 lseek 以相反的顺序从文件中读取字符。
到目前为止,我有:
int finished = 1;
char temp[1];
while (finished > 0) {
lseek(fileID,0,2);
finished = read(fileID, &temp, 1);
cout << temp[0];
}
但读取总是返回 0。
有什么想法吗?
最佳答案
当然应该调用 lseek()
lseek(fileID, -1, SEEK_END);
您正在寻找文件末尾,您需要少一个字节。
关于c++ - 如何使用lseek读取文件的最后一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4732592/