gpt4 book ai didi

c++ - 在 Visual Studio 2010 中将输出消息写入 'output window' 的最简单方法?

转载 作者:IT老高 更新时间:2023-10-28 22:07:12 24 4
gpt4 key购买 nike

我已经尝试过 OutputDebugString 函数,但大多数时候我都会收到如下错误:

error C2664: 'OutputDebugStringA' : cannot convert parameter 1 from 'int' to '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);

最佳答案

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

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

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

关于c++ - 在 Visual Studio 2010 中将输出消息写入 'output window' 的最简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3179199/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com