問題描述
我有一個已加載到 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 應用程序中的調試輸出窗口?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!