我试过OutputDebugString
功能,大部分的时间,我得到错误,如:在Visual Studio 2010中将输出消息写入“输出窗口”的最简单方法?
error C2664: 'OutputDebugStringA' : cannot convert parameter 1 from 'int' to 'LPCSTR'
请建议。谢谢。
我试过OutputDebugString
功能,大部分的时间,我得到错误,如:在Visual Studio 2010中将输出消息写入“输出窗口”的最简单方法?
error C2664: 'OutputDebugStringA' : cannot convert parameter 1 from 'int' to 'LPCSTR'
请建议。谢谢。
它只接受一个字符串作为参数,而不是一个整数。尝试类似
sprintf(msgbuf, "My variable is %d\n", integerVariable);
OutputDebugString(msgbuf);
欲了解更多信息看一看http://www.unixwiz.net/techtips/outputdebugstring.html
要使用的OutputDebugString(),提供char *
或const char *
作为参数:
OutputDebugString("This is an output");
我所知道的最常用的方法是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);
看来TRACE是在MFC中定义的,我没有使用它。 – understack 2010-07-05 17:13:07
我发现这在搜索错误消息时回答: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);
绝不是我一个专家,我只是发现一些工作,并继续前行。
如果我想格式化字符串并将数据传递给它,那么这并不占用。 – 2017-03-23 05:04:07
我添加了适用于注射的解决方案。我专注于iOS平台和语言,请不要将此视为专家解决方案:) – Jangles 2017-03-24 16:06:37
用途:
OutputDebugStringA("Some random text");
或者:
OutputDebugString(L"Some random text");
考虑使用sprintf_s – 2010-07-05 12:00:16
+ @乔恩:即使是更好的,可以考虑使用的std :: stringstream的。 – 2010-07-05 12:28:04
@Billy ONeal:我建议你使用std :: stringstream而不是sprintf/sprintf_s。谢谢。 – understack 2010-07-05 17:05:43