Logging errors in electron

Hello,
I am using Electron for tracking. At times sending of data to the server with TCPClient::write() fails. I would like to log the error into a file and then analyse them later.
Has anyone tried this before? Is it actually possible to create a file in the device for logging errors? Why I want to log into a file because I want the errors to survive electron reboot. I have tried using ofstream but the code fails to link once I included fstream :

It looks like this is not supported.
The code I wanted to use is pretty simple:

ofstream f;
f.open (ERROR_FILE, ios::in | ios::app);
if (f != NULL) {
f << msg <<"\n";
f.close();
}

Maybe there is a better way to do this!
Thanks