Suppose that I have the following code:
#include <chrono> #include <fstream> #include <thread> int main() { std::ofstream f("test.log"); int i = 0; while (true) { f << i++; f.flush(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); } } (note that I have a flush call after each write operation)
I noticed that this application doesn't update "last modified time" and "size" attributes of the "test.log" file unless I do a right-click on this file or open it.
I guess that this is due to an internal bufferization (system doesn't want to make such time-consuming operations as an actual I/O to disk unless forced to do so). Am I right?
I need to write an application that should watch for changes in log files created by other applications (I can't change them). At first, I thought about FileSystemWatcher class in C# but I noticed that it has the same behavior (it doesn't fire a corresponding event unless file was closed in a source application or was forced to update by right-clicking that file in Windows Explorer). What can I do then? Call WinAPI functions like GetFileAttributes for every file that I want to look for as often as I can?
flushes made by other applications