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

标签 c++ visual-studio visual-studio-2010

我已经尝试过 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/

相关文章:

c++ - 让 dll 包含在 Visual Studio 中工作

c++ - 基于 OpenCV C++ 光流的分割代码抛出异常

vb.net - 源代码保护

c++ - std::copy_n 中的执行策略的真正含义是什么?

c++ - 迷宫求解程序的回溯逻辑错误

visual-studio - 有没有办法在 Wix 中制作 32 位和 64 位组合安装程序?

c# - 如何根据所选配置将项目构建为可移植或普通类库?

visual-studio-2010 - 如何解决 Visual Studio 2010 中的“不支持 “Validation (): Element ‘x’”警告

c++ - 好友功能无法访问的成员

c++ - 有关C++中函数的默认返回类型的查询