Std::cerr doesn't work for me in VS 2019

I’m using std:cerr successfully on MacOs to print debug messages to the debugger output pane.

But for some reason, on Windows in VS 2019, it prints nothing to the output pane.

Does anyone have an idea of why that might be?

Here’s an example:

std::cerr << String::formatted("(1) ========== w %03d, textW %03d", w, (int) textLayout.getWidth()) << "\n";

If instead I replace it with this, it works as expected:

String s = String::formatted("(1) ========== w %03d, textW %03d", w, (int)textLayout.getWidth());

Visual Studio ‘Output’ panel doesn’t use the stderr pipe as a source. If you dig into the DBG macro you will find it writes to OutputDebugString, which is a special Windows method for communicating with the debugger if present.

DBG on both platforms will do what you want. You shouldn’t be using stderr for anything other than error messages.

Thank you. It’s strange because if you search this site for std::cerr, there are many examples of source code using it for debugging purposes…


Both std::cout and std::cerr is fine to use, You would see cout/cerr output if you executed your code from the command line/terminal, It’s only when you’re running your program inside a debugger that things are a little different.

Typically you would use the DBG macro for text you wouldn’t normally want anyone to see in normal operation, Infact the macro does nothing when you build your program in release mode.

cout/cerr is used for text you do want printed, Normal messages and Error messages respectfully.

1 Like

OK, thank you for the explanation!