The following code will print something to a file
std::fstream fout ("D_addr.txt", std::fstream::app);
fout << pkt->Addr() << std::endl;
flush(fout);
fout.close();
While debugging, I watched pkt->Addr() and it has some values. The fout line is passed without problem. Also the file D_addr.txt is created. However after closing the file, the file size is zero! nothing has been written to it.
Where is the problem?
This is not your actual code I guess and if it is I would start with that
Addr()function of yours.Note that fstream::close “closes the file currently associated with the object, disassociating it from the stream. Any pending output sequence is written to the physical file.”
flush(fout);can be omitted.You should also specify
std::fstream::outflag. “If the function is called with any value in that parameter the default mode is overridden, not combined.” So instead ofstd::fstream::appyou should passstd::fstream::app | std::fstream::out.