什么是`fseek`,`lseek`,`seekg`,之间的区别`seekp`?

编程入门 行业动态 更新时间:2024-10-28 00:21:39
本文介绍了什么是`fseek`,`lseek`,`seekg`,之间的区别`seekp`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我被面试官问我将如何实现尾(是的,一个在Linux的shell)。我的回答是,首先寻求到文件的末尾,然后读取字符一个接一个向前,如果遇到一个 \\ n ,意味着一条线是下降,等等等等等等。我想我的答案是正确的。

I was asked by an interviewer that how would I implement tail (yes, the one in linux shell). My answer was, first seek to the end of the file, then read characters one-by-one forward, if encounters a \n, means one line is down, blah blah blah. I assume my answer is correct.

然后我发现这个问题,这求我应该使用实施尾?我以为我可以简单地使用 seekg (C ++的事情吗?),但有人告诉我,我应该使用 lseek的(Linux的系统调用?)。

Then I found this problem, which seek should I use to implement tail? I thought I can simply use seekg (C++ thing?), but I was told that I should use lseek (linux system call?).

因此​​包括 fseek的(ANSI C的东西?),其中一个我应该用实施尾?而且是它们之间有很大的区别?

So including fseek (ANSI C thing?), which one should I use to implement tail? And is there any big difference between them?

推荐答案

使用 seekg 使用C ++输入输出流库时。 seekp 是没有用在这里,因为它集认沽指针。

Use seekg when using the C++ IOstreams library. seekp is no use here, since it sets the put pointer.

使用 fseek的使用C stdio库时。使用使用低级别POSIX文件描述符时 lseek的 I / O。

Use fseek when using the C stdio library. Use lseek when using low-level POSIX file descriptor I/O.

之间的各种查找功能不同的是刚才那种文件/流对象在其经营。在Linux上, seekg 和 fseek的很可能在 lseek的。

The difference between the various seek functions is just the kind of file/stream objects on which they operate. On Linux, seekg and fseek are probably implemented in terms of lseek.

更多推荐

什么是`fseek`,`lseek`,`seekg`,之间的区别`seekp`?

本文发布于:2023-10-07 20:05:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470404.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   lseek   fseek   seekp   seekg

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!