Basically, the idea is I can log stuff to a file as my program runs.
The problem is that after running my program, I realize that a good amount of my traces are missing, most are out of order, and finally, a lot of them are missing the beginning or end of the message, like this:
Code:
/main.cpp at line 28 there
ne 33 here
/EnColor.h at line 33 hello
What am I doing wrong? I thought std::endl was supposed to flush my stream, doesn't that mean this shouldn't happen?
Do I have a broken declaration of log_stream, and actually have several handles on the same file?
Is this an ofstream problem, or what? What would you guys do?
PS: Codeblocks with mingw on winxp32
PS2, replacing log_stream with the standard std::cout works fine, but that is not what I want
Last edited by monarch_dodra; January 28th, 2010 at 11:30 AM.
Do I have a broken declaration of log_stream, and actually have several handles on the same file?
Yes you will have a more than one instance of log_stream. One for each module that you have included that header.
That's how static variables work. They are only visible from inside the module they are declared. That's why the linker doesn't complain.
Declare it extern in the header and create only one in your main module.
Kurt
Last edited by ZuK; January 28th, 2010 at 12:01 PM.
Yes you will have a more than one instance of log_stream. One for each module that you have included that header.
That's how static variables work. They are only visible from inside the module they are declared. That's why the linker doesn't complain.
Declare it extern in the header and create only one in your main module.
Kurt
Wow, after 1.5 years of coding C++ proffesionally, and I didn't even know that. Now I do though.
Bookmarks