How do I print to the debug output window in a Win32 app?(如何打印到 Win32 应用程序中的调试输出窗口?)
问题描述
我有一个已加载到 Visual Studio 2005 中的 win32 项目.我希望能够将内容打印到 Visual Studio 输出窗口,但我终生无法弄清楚如何.我试过 'printf' 和 'cout <<'但我的消息顽固地没有打印出来.
I've got a win32 project that I've loaded into Visual Studio 2005. I'd like to be able to print things to the Visual Studio output window, but I can't for the life of me work out how. I've tried 'printf' and 'cout <<' but my messages stay stubbornly unprinted.
是否有某种特殊的方式可以打印到 Visual Studio 输出窗口?
Is there some sort of special way to print to the Visual Studio output window?
推荐答案
您可以使用 OutputDebugString.OutputDebugString 是一个宏,根据您的构建选项映射到 OutputDebugStringA(char const*) 或 OutputDebugStringW(wchar_t const*).在后一种情况下,您必须为该函数提供一个宽字符串.要创建宽字符文字,您可以使用 L 前缀:
You can use OutputDebugString. OutputDebugString is a macro that depending on your build options either maps to OutputDebugStringA(char const*) or OutputDebugStringW(wchar_t const*). In the later case you will have to supply a wide character string to the function. To create a wide character literal you can use the L prefix:
OutputDebugStringW(L"My output string.");
通常,您会像这样将宏版本与 _T 宏一起使用:
Normally you will use the macro version together with the _T macro like this:
OutputDebugString(_T("My output string."));
如果您的项目配置为为 UNICODE 构建,它将扩展为:
If you project is configured to build for UNICODE it will expand into:
OutputDebugStringW(L"My output string.");
如果您不是为 UNICODE 构建,它将扩展为:
If you are not building for UNICODE it will expand into:
OutputDebugStringA("My output string.");
这篇关于如何打印到 Win32 应用程序中的调试输出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何打印到 Win32 应用程序中的调试输出窗口?
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 初始化列表*参数*评估顺序 2021-01-01
