I have declared one static fstream file under header.h
static ofstream myfile_logs("D:\\Elec...");
myfile_logs << "verify...";
//end of main .cpp
myfile_logs << "calculate Mem";
//end of cal_mem
When i run this program, on opening the log file
i get only
"calculate Mem" text displayed
the control does come to verify_data but the file is not appended or updated with verify.. text
The log file seems to work only for commonFunc.cpp
how to have this log file appended for multiple cpps?
You have created two separate streams, one in main.cpp and one in commonFunc.cpp. Even though they both use the same filename they will not be synchronised. You should create a function that manages the file and does all the logging, and call that from the other parts of your program.
The static doesn't do what you're assuming. In a class it makes it "global" (shared by all instances) but at namespace scope it makes the variable private to the compilation unit. Every file that includes your header has it's own stream.
I am looking for a C++ library like syslog-ng[^] but with the possibility to run under Windows (syslog-ng needs a POSIX system ). Has anyone an idea or a suggestion?
Not required anymore, I simply took a hour-long Google search on me and made my Windows POSIX-compatible [^] . Since syslog-ng needs POSIX I suppose it will run well and smooth...
FYI... if you're required to export your application to end users, Cygwin might still be an easier option. You may be surprised at the number of commercial applications that rely on Cygwin to run on Windows.
thank you for the information, but I am talking about the controller software of this medical diagnostics instrument[^] (pointed that not well enough out, sorry). Because of the regulations in the market we are going to do a hardening process on the OS anyways and can set up the image anyway we want to, so installing the kernel patch is no problem since we decide what the customers OS will look like. And using the kernel patch we get a faster response time anyways, so this is the way to go for us.
But thank you very much for the additional info.
i am trying to write a program that counts the no. of records in a file by placing the get pointer at the end of file and using tellg() function to get the pointer position and dividing the no. of bytes with the size of one record to get the no. of total records
but when i write
and then inquire the position of get pointer
the result that i am getting is -1.
please tell me what am i doing wrong?