void __cdecl OutputDebugPrintf(const char* format, ...) { va_list vlArgs; char* strBuffer = (char*)GlobalAlloc(GPTR, 4096); va_start(vlArgs, format); //_vsnprintf(strBuffer, 4096 - 1, format, vlArgs); int size = strlen(strBuffer) -1; _vsnprintf_s(strBuffer, size, 4096 - 1, format, vlArgs); va_end(vlArgs); //strcat(strBuffer, "\n"); strcat_s(strBuffer, size, "\n");//这里字符串必须以 '\n' 结尾 OutputDebugStringA(strBuffer); GlobalFree(strBuffer); return; }
//调用方法:
OutputDebugPrintf("hello world %d",123);
按下f5进入调试模式才能打印结果,如果不调试则看不到输出
// 头文件 #include <stdio.h> #include <stdarg.h>
标签:输出,format,vlArgs,char,vs,va,控制台,strBuffer,size From: https://www.cnblogs.com/laremehpe/p/17442012.html