In C ++, I want to make a loop that constantly checks the size of a file and does something if the size changes


I'm trying to make a program that will constantly check the size of a file and if the size of the file changes, make the program do something. The file is an html file so another method could be to constantly check the source of it and if the number of characters changes, do something.

I think I could do that without much trouble but the thing I'm having a problem with is having something constantly check the file. Is there a function that can do that? I'd like it to check every 10 seconds.

edit: The operating system is Windows 7 64-bit

For Windows, you can use the File Change Notification API and have the OS call you when the item you're watching changes. Until that happens, your thread can sleep.

Having the OS call you is much preferred over setting up an infinite polling loop. If you run your polling loop without any sleeps, you'll peg the CPU at 100% utilization, force the fans to spool up to get rid of the extra heat, and deplete the laptop battery in 5 minutes. ;>