[英]Simplest way to write output message to 'output window' in Visual Studio 2010?
我試過OutputDebugString
函數,大部分時間我都會得到如下錯誤:
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
我知道的最常見的方法是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 );
我在搜索錯誤消息時找到了這個答案: https : //stackoverflow.com/a/29800589
基本上,在使用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");
或者:
OutputDebugString("Some random text");
要使用 OutputDebugString(),請提供char *
或const char *
作為參數:
OutputDebugString("This is an output");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.