How to write to the Output window in Visual Studio?

前端 未结 7 2037
小鲜肉
小鲜肉 2021-01-30 02:39

Which function should I use to output text to the \"Output\" window in Visual Studio?

I tried printf() but it doesn\'t show up.

7条回答
  •  一向
    一向 (楼主)
    2021-01-30 03:41

    Even though OutputDebugString indeed prints a string of characters to the debugger console, it's not exactly like printf with regard to the latter being able to format arguments using the % notation and a variable number of arguments, something OutputDebugString does not do.

    I would make the case that the _RPTFN macro, with _CRT_WARN argument at least, is a better suitor in this case -- it formats the principal string much like printf, writing the result to debugger console.

    A minor (and strange, in my opinion) caveat with it is that it requires at least one argument following the format string (the one with all the % for substitution), a limitation printf does not suffer from.

    For cases where you need a puts like functionality -- no formatting, just writing the string as-is -- there is its sibling _RPTF0 (which ignores arguments following the format string, another strange caveat). Or OutputDebugString of course.

    And by the way, there is also everything from _RPT1 to _RPT5 but I haven't tried them. Honestly, I don't understand why provide so many procedures all doing essentially the same thing.

提交回复
热议问题