Question

I have a program written in C++ that I'm trying to debug.

When I wrote the first few versions of my program, I included several cout statements to print to the console so I could debug. Now, my program's grown to several thousand lines with several hundred cout statements. I have a rare bug that only occurs if I run the program a few thousand times, so even though my console screen buffer is 9999, I still don't see all of my debugging output.

I know that I could create a file stream and write some code to output to a file under each cout statement, but since I have so many cout statements it would take me a while to do this.

I'm new to C++ so I just wanted to see if anyone knew of a faster alternative before I edit all of my source code. Thanks.

Edit: I'm running the program on Windows.

Was it helpful?

Solution

I wouldn't recommend changing the source just for that. In Linux (or Cygwin) environment just pipe your output to tee. If you don't have tee to your disposal, it takes about 20 minutes to write.

Edit: The core of tee is

FILE * file = fopen("outfilename", "wb");
char buffer[BUFFER_SIZE];
while(fgets(buffer, BUFFER_SIZE, stdin)) {
    fputs(buffer, stdout);
    fputs(buffer, file);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top