How can it possibly work? You open
myfile
but print some
ipSrc
(and you don't even show its declaration) using some
printf
who knows where. The declaration of
ipSrc
is important. Do you have an operator
<<
for it? According to your format, it must be a string.
This is a right pattern of using
ofstream
:
#include <iostream>
#include <fstream>
using namespace std;
ofstream outfile ("test.txt");
myfile << "\n Source IP: " << ipSrc;
outfile.close();
You can also use format, of course, but to combine it with
<<
you will need to use different function, to print data into
char*
buffer:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/[
^].
—SA