Simplest way to write output message to #39;output window#39; in Visual Studio 2010?(在 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 中将输出消息写入“输出窗口"的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Visual Studio 2010 中将输出消息写入“输出窗口


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01