Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

error C2664: 'OutputDebugStringA' : cannot convert parameter 1 from 'int' to 'LPCSTR'

Examples

Attempt 1:

//ERROR: sprintf is unsafe. Use sprintf_s instead
int x = 4;
char s[256];
sprintf(s, "There is %d numbers", x);
OutputDebugString((LPCWSTR)s);

Attempt 2:

//FAIL: outputs junk (sprintf_s doesn't understand unicode?)
int x = 4;
char s[256];
sprintf_s(s, "There is %d numbers", x);
OutputDebugString((LPCWSTR)s);

Attempt 3:

//ERROR: no instance of overloaded function "sprintf_s" matches the argument list
int x = 4;
TCHAR s[256];
sprintf_s(s, "There is %d numbers", x);
OutputDebugString((LPCWSTR)s);

Attempt 4:

//ERROR: no instance of overloaded function "sprintf_s" matches the argument list
int x = 4;
TCHAR s[256];
sprintf_s(s, L"There is %d numbers", x);
OutputDebugString((LPCWSTR)s);

Attempt 5:

//ERROR: no instance of overloaded function "swprintf" matches the argument list
int x = 4;
TCHAR s[256];
swprintf(s, "There is %d numbers", x);
OutputDebugString(s);

Attempt 6:

//ERROR: 'swprintf': function has been changed to confirm with the ISO C standard, adding an extra character count parameter
int x = 4;
TCHAR s[256];
swprintf(s, L"There is %d numbers", x);
OutputDebugString(s);
like image 878
understack Avatar asked Jul 05 '10 11:07

understack


2 Answers

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

like image 58
peter_mcc Avatar answered Oct 14 '22 03:10

peter_mcc


For debugging purposes you could use _RPT macros.

For instance,

_RPT1( 0, "%d\n", my_int_value );
like image 32
Kirill V. Lyadvinsky Avatar answered Oct 14 '22 04:10

Kirill V. Lyadvinsky