I am logging some data into a .txt file during a program execution. The problem is that sometimes I need to cut the power to the system, but I would still like to save the written data.
Here is the code I use to write on the txt file:
std::ofstream file; // placed inside the header file
file.open("filename.txt"); // placed in the class constructor
file << "data " << std::endl; // repeatedly called inside a loop
The data is flushed during the execution, since I open the file while the program is running and I see the updates. But if I cut the power, the result is an empty file, or only one line written on it. I've also tried to manually flush(), but that didn't work either. The OS is Linux Yocto Poky.