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.
Have a look at inotify on Linux or kqueue on Mac OS.
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.