我已经尝试过 OutputDebugString
功能,但大多数时候我会收到如下错误:
错误 C2664:“OutputDebugStringA”:无法将参数 1 从“int”转换为“LPCSTR”
例子
尝试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);
尝试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);
尝试 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);
尝试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);
尝试 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);
尝试 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);
原文由 understack 发布,翻译遵循 CC BY-SA 4.0 许可协议
它只接受字符串作为参数,而不接受整数。尝试类似的东西
有关更多信息,请查看 http://www.unixwiz.net/techtips/outputdebugstring.html