C++ 将输出消息写入';输出窗口';在VisualStudio2010中?
我尝试了C++ 将输出消息写入';输出窗口';在VisualStudio2010中?,c++,visual-studio,visual-studio-2010,C++,Visual Studio,Visual Studio 2010,我尝试了OutputDebugString函数,大多数时候都会出现如下错误: error C2664: 'OutputDebugStringA' : cannot convert parameter 1 from 'int' to 'LPCSTR' 请建议。谢谢。要使用OutputDebugString(),请提供char*或const char*作为参数: OutputDebugString("This is an output"); 它只接受字符串作为参数,而不是整数。试试像这样的东西
OutputDebugString
函数,大多数时候都会出现如下错误:
error C2664: 'OutputDebugStringA' : cannot convert parameter 1 from 'int' to 'LPCSTR'
请建议。谢谢。要使用OutputDebugString(),请提供char*
或const char*
作为参数:
OutputDebugString("This is an output");
它只接受字符串作为参数,而不是整数。试试像这样的东西
sprintf(msgbuf, "My variable is %d\n", integerVariable);
OutputDebugString(msgbuf);
有关更多信息,请查看,以便进行调试 比如说,
_RPT1( 0, "%d\n", my_int_value );
我知道的最常见的方法是
跟踪
宏:
例如:
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 );
我在搜索错误消息时找到了此答案: 基本上,使用
OutputDebugString
时,只需在输出字符串前面加一个“L”:
OutputDebugString(L"test\n");
这对我很有效
编辑:
对于使用数据格式化字符串,我最终使用
char buffer[100];
sprintf_s(buffer, "check it out: %s\n", "I can inject things");
OutputDebugStringA(buffer);
我决不是一个专家,我只是找到了一些有用的东西并继续前进。使用:
OutputDebugStringA("Some random text");
或:
+@乔恩:更好的是,考虑使用STD::StrugStudio。@ Billy ONeal:我使用STD::StrugStand,而不是SaveTf/SaveTffs,正如您所建议的。谢谢。@BillyONeal您能解释一下为什么使用stringstream会更好吗?只是好奇。@2017年的特雷弗哈特法案与2010年的法案并不完全一致。主要的优点是不需要担心目标缓冲区的大小。但是sprintf有很多用途:)似乎跟踪是在MFC中定义的,我没有使用它。如果我想格式化字符串并将数据传递给它,这还不能解释。我添加了我的解决方案,用于注入。我专门研究iOS平台和语言,请不要将此视为专家解决方案:)根据您的编译器选项和设置,
OutputDebugString
被翻译成两个目标之一,OutputDebugStringW
用于宽文本字符(wchart\u t
)或OutputDebugStringA
用于窄文本字符(char
)。创建wchar\u t
宽字符串时需要L
,如L“宽字符”
与窄字符“
所示。sprintf_s()
函数使用窄字符,标准的char
类型,因此char缓冲区[100]使用OutputDebugStringA()
将内容打印到输出窗口,以强制使用窄字符文本。
OutputDebugString("Some random text");