How to view printf output in a Win32 application on Visual Studio 2010?

后端 未结 7 1492
梦如初夏
梦如初夏 2021-02-01 05:48

How can you view printf output in a Win32 application (entering with a WinMain) in Visual Studio 2010?

7条回答
  •  名媛妹妹
    2021-02-01 06:00

    Another way which wouldn't require changing existing printf's and also print to VS output window would go something like this:

    #define printf printf2
    
    int __cdecl printf2(const char *format, ...)
    {
        char str[1024];
    
        va_list argptr;
        va_start(argptr, format);
        int ret = vsnprintf(str, sizeof(str), format, argptr);
        va_end(argptr);
    
        OutputDebugStringA(str);
    
        return ret;
    }
    
    ...
    
    printf("remains %s", "the same");
    

提交回复
热议问题