How to write to the Output window in Visual Studio?

前端 未结 7 2033
小鲜肉
小鲜肉 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:44

    Use OutputDebugString instead of afxDump.

    Example:

    #define _TRACE_MAXLEN 500
    
    #if _MSC_VER >= 1900
    #define _PRINT_DEBUG_STRING(text) OutputDebugString(text)
    #else // _MSC_VER >= 1900
    #define _PRINT_DEBUG_STRING(text) afxDump << text
    #endif // _MSC_VER >= 1900
    
    void MyTrace(LPCTSTR sFormat, ...)
    {
        TCHAR text[_TRACE_MAXLEN + 1];
        memset(text, 0, _TRACE_MAXLEN + 1);
        va_list args;
        va_start(args, sFormat);
        int n = _vsntprintf(text, _TRACE_MAXLEN, sFormat, args);
        va_end(args);
        _PRINT_DEBUG_STRING(text);
        if(n <= 0)
            _PRINT_DEBUG_STRING(_T("[...]"));
    }
    
    0 讨论(0)
提交回复
热议问题