NO

Author Topic: Redirct stdout to file  (Read 4332 times)

JohnF

  • Guest
Redirct stdout to file
« on: August 01, 2007, 07:58:40 AM »
When debugging a large project it is sometimes convenient to print to a file. Instead of using fprintf and carrying around a file handle you can redirect stdout to a file and use printf.

As an example, at the top of WinMain

    fclose(stdout);
    *stdout = *fopen("c:\\debug.log", "w");

Then use printf throughout the project.

stdout is closed on exit but one could close it manually before one exits.

    fclose(stdout);

I don't know if this is considered bad practice but it works.

John

xanatose

  • Guest
Re: Redirct stdout to file
« Reply #1 on: November 03, 2008, 10:18:46 PM »
you can also use
Code: [Select]
freopen("file.txt","wt",stdout);