实现“tail-f”在C ++中 [英] Implement "tail -f" in C++

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

问题描述

我想在C ++中创建一个与tail-f具有相同功能的小代码:在一个文本文件中观察新行并在标准输出中显示它们。

I want to create a small code in C++ with the same functionality as "tail-f": watch for new lines in a text file and show them in the standard output.

这个想法是有一个监视文件的线程

The idea is to have a thread that monitors the file

有没有简单的方法来做,没有每次打开和关闭文件?

Is there an easy way to do it without opening and closing the file each time?

推荐答案

请查看

Inotify 是Linux内核子系统,允许您订阅文件上的事件,它会在您的文件上发生偶发事件时向您的应用程序报告。

Inotify is Linux kernel subsystem that allows you to subscribe for events on files and it will report to your application when the even happened on your file.

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

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