Simplest way to write output message to 'output window' in Visual Studio 2010?

后端 未结 6 1665
难免孤独
难免孤独 2020-12-30 01:32

I\'ve tried OutputDebugString function and most of the time I get error like :

error C2664: \'OutputDebugStringA\' : cannot convert parameter 1          


        
相关标签:
6条回答
  • 2020-12-30 01:40

    I found this answer when searching the error message: https://stackoverflow.com/a/29800589

    Basically, you just need put an "L" in front of your output string when using OutputDebugString:

    OutputDebugString(L"test\n");

    It worked great for me.

    Edit:

    For formatting strings with data, I ended up using

    char buffer[100]; sprintf_s(buffer, "check it out: %s\n", "I can inject things"); OutputDebugStringA(buffer);

    By no means am I an expert, I just found something that worked and moved on.

    0 讨论(0)
  • 2020-12-30 01:42

    To use OutputDebugString(), provide char * or const char * as parameter:

    OutputDebugString("This is an output");
    
    0 讨论(0)
  • 2020-12-30 01:49

    The most common way I'm aware of is the TRACE macro:

    http://msdn.microsoft.com/en-us/library/4wyz8787%28VS.80%29.aspx

    For example:

    int x = 1;
    int y = 16;
    float z = 32.0;
    TRACE( "This is a TRACE statement\n" );
    
    TRACE( "The value of x is %d\n", x );
    
    TRACE( "x = %d and y = %d\n", x, y );
    
    TRACE( "x = %d and y = %x and z = %f\n", x, y, z );
    
    0 讨论(0)
  • 2020-12-30 01:58

    For debugging purposes you could use _RPT macros.

    For instance,

    _RPT1( 0, "%d\n", my_int_value );
    
    0 讨论(0)
  • 2020-12-30 02:00

    It only accepts a string as a parameter, not an integer. Try something like

    sprintf(msgbuf, "My variable is %d\n", integerVariable);
    OutputDebugString(msgbuf);
    

    For more info take a look at http://www.unixwiz.net/techtips/outputdebugstring.html

    0 讨论(0)
  • 2020-12-30 02:02

    Use:

    OutputDebugStringA("Some random text");
    

    Or:

    OutputDebugString("Some random text");
    
    0 讨论(0)
提交回复
热议问题