在 Visual Studio 2010 中将输出消息写入“输出窗口"的最简单方法?

时间:2023-03-09
本文介绍了在 Visual Studio 2010 中将输出消息写入“输出窗口"的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经尝试过 OutputDebugString 函数,但大部分时间我都会遇到如下错误:

I've tried OutputDebugString function and most of the time I get error like :

错误 C2664:OutputDebugStringA":无法将参数 1 从int"转换为LPCSTR"

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);

推荐答案

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

It only accepts a string as a parameter, not an integer. Try something like

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

有关更多信息,请查看 http://www.unixwiz.net/techtips/outputdebugstring.html

For more info take a look at http://www.unixwiz.net/techtips/outputdebugstring.html

这篇关于在 Visual Studio 2010 中将输出消息写入“输出窗口"的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 Windows 中使用 C++ 的颜色控制台输出 下一篇:通过引用将参数传递给 std::async 失败

相关文章