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 中将输出消息写入“输出窗口
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
