How to write to the Output window in Visual Studio?

前端 未结 7 2044
小鲜肉
小鲜肉 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

    Useful tip - if you use __FILE__ and __LINE__ then format your debug as:

    "file(line): Your output here"
    

    then when you click on that line in the output window Visual Studio will jump directly to that line of code. An example:

    #include 
    #include 
    #include 
    
    void DBOut(const char *file, const int line, const WCHAR *s)
    {
        std::wostringstream os_;
        os_ << file << "(" << line << "): ";
        os_ << s;
        OutputDebugStringW(os_.str().c_str());
    }
    
    #define DBOUT(s)       DBOut(__FILE__, __LINE__, s)
    

    I wrote a blog post about this so I always knew where I could look it up: https://windowscecleaner.blogspot.co.nz/2013/04/debug-output-tricks-for-visual-studio.html

提交回复
热议问题