C ++中的tail -f实现 [英] tail -f implementation in C ++

查看:469
本文介绍了C ++中的tail -f实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


采访中有人问我这个问题.如何在C或C ++中实现等效于Unix命令tail -f的功能.有人可以指教吗.

我认为我们应该使用ftell,fseek,但不是很确定.

谢谢,
Ganesh

Hi,
I was asked this question in an interview. How to implement the equivalent of Unix command tail -f in C or C++. Can someone please advise.

I think we should use ftell, fseek, but not quite sure though.

Thanks,
Ganesh

推荐答案

为什么不只是阅读tail的源代码或尝试实现它? :)
why not just read tail''s source code or try to implement it? :)


我将使用getline函数并进行递归.
I would use the getline function and recursion.


我认为当被问到这样的问题时,文件更改通知是关键.不是读取文件的方式,因为每个人都知道如何读取文件.

FindFirstChangeNotification()在Windows上可以使用WaitForXxxObject(),然后再使用WaitForXxxObject()可以避免使用计时器.

可能不需要在采访中知道这些函数的名称,但是了解它们并描述该技术更有价值.
I think the file change notification is the key when asked a question like that. Not how you read a file, because everyone knows how to read a file.

FindFirstChangeNotification() would work on windows followed by a WaitForXxxObject()to avoid having a timer.

Knowing the names of the functions is probably not necessary at an interview, but knowing about them and describing the technique is more valuable.


这篇关于C ++中的tail -f实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆