如何在Visual Studio 2010的Win32应用程序中查看printf输出? [英] How to view printf output in a Win32 application on Visual Studio 2010?
本文介绍了如何在Visual Studio 2010的Win32应用程序中查看printf输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Visual Studio 2010 ?
推荐答案
严格回答您的问题,您可以使用 winbase.h OutputDebugString
函数.
Strictly answering your question, you may use printf-like functions in a Win32 application in Visual Studio 2010 using the winbase.h OutputDebugString
function.
我写了一个简单的程序来演示如何做.
I wrote a simple program that shows how to do it.
#include <windows.h>
#include <stdio.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdShow, int nCmdShow)
{
int number = 10;
char str[256];
sprintf_s(str, "It works! - number: %d \n", number);
OutputDebugString(str);
return 0;
}
OutputDebugString
函数将LPCSTR
作为参数.我在打印前用sprintf_s
格式化了字符串.
The OutputDebugString
function takes an LPCSTR
as a parameter. I used the sprintf_s
to format the string before printing.
这会将结果打印到Visual Studio 2010输出窗口.
This would print the result to the Visual Studio 2010 output window.
希望对您有帮助!
这篇关于如何在Visual Studio 2010的Win32应用程序中查看printf输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文