Where does fprintf(stderr, ..) go to?

G

Guest

Sorry if this is a trivial question :)

I've got several print statements in my code:

fprintf ( stderr, ....);

but when I run my program, I cannot find the output text in any window.

My program is in Visual C++. The program is windows-based (not a
command-line program. The program is not managed. I'm running within the
Visual C++ debugger. I've tried displaying every Vis C++ window, including
the "Output" window, but the fprintf() text does not appear there.

What window contains the fprintf(stderr) text (when running in the debugger)?
 
W

William DePalo [MVP VC++]

noleander said:
Sorry if this is a trivial question :)

I've got several print statements in my code:

fprintf ( stderr, ....);

but when I run my program, I cannot find the output text in any window.

My program is in Visual C++. The program is windows-based (not a
command-line program. The program is not managed. I'm running within
the
Visual C++ debugger. I've tried displaying every Vis C++ window,
including
the "Output" window, but the fprintf() text does not appear there.

What window contains the fprintf(stderr) text (when running in the
debugger)?

Windows programs do not have consoles by default. Consoles are the devices
to which stdout and stderr are usually wired. Catch 22.

If you want to see output in the debugger you can use OutputDebugString().

If you want a console for debugging your windows applications you can do
this:

FILE *fp;
HANDLE hCon;

// Allocate a console

AllocConsole();

// And make printf happy

hCon = GetStdHandle(STD_OUTPUT_HANDLE);

fd = _open_osfhandle(reinterpret_cast<long>(hCon), 0);
fp = _fdopen(fd, "w");

*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);

Regards,
Will
 
G

Guest

Thanks for the prompt and accurate reply.

Using OutputDebugString() works perfectly for me!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top