I\'m trying to write the contents of buf pointer to the file created by ofstream.
For some reason the file is empty, however the contents of buf is never empty... What
You need to flush the ofstream before closing it. Try ofstr.flush(); before ofstr.close(); I had this error some time ago when I thought that closing the stream automatically flushes it but, as it turned out, it doesn't.
ofstr.flush();
ofstr.close();