2010-07-05 77 views

回答

20

它只接受一个字符串作为参数,而不是一个整数。尝试类似

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

欲了解更多信息看一看http://www.unixwiz.net/techtips/outputdebugstring.html

+4

考虑使用sprintf_s – 2010-07-05 12:00:16

+4

+ @乔恩:即使是更好的,可以考虑使用的std :: stringstream的。 – 2010-07-05 12:28:04

+1

@Billy ONeal:我建议你使用std :: stringstream而不是sprintf/sprintf_s。谢谢。 – understack 2010-07-05 17:05:43

0

要使用的OutputDebugString(),提供char *const char *作为参数:

OutputDebugString("This is an output"); 
9

为了调试的目的,你可以使用_RPT macros

例如,

_RPT1(0, "%d\n", my_int_value); 
9

我所知道的最常用的方法是TRACE宏:

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

例如:

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

看来TRACE是在MFC中定义的,我没有使用它。 – understack 2010-07-05 17:13:07

2

我发现这在搜索错误消息时回答:https://stackoverflow.com/a/29800589

基本上,你只需要在你的输出字符串前面放一个“L”使用OutputDebugString时:

OutputDebugString(L"test\n");

这对我来说真是棒极了。

编辑:

对于数据格式化字符串,我结束了使用

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

绝不是我一个专家,我只是发现一些工作,并继续前行。

+0

如果我想格式化字符串并将数据传递给它,那么这并不占用。 – 2017-03-23 05:04:07

+0

我添加了适用于注射的解决方案。我专注于iOS平台和语言,请不要将此视为专家解决方案:) – Jangles 2017-03-24 16:06:37

0

用途:

OutputDebugStringA("Some random text"); 

或者:

OutputDebugString(L"Some random text");