C/C++语言的函数可以定义可变参数,例子如下:
#include <windows.h>
#include <cstdio>
#include <tchar.h>
void DebugMsg(LPCTSTR pszFormat, ...);
int main()
{
DebugMsg(_T("%s\n"), _T("hello"));
return 0;
}
void DebugMsg(LPCTSTR pszFormat, ...)
{
TCHAR buf[1024] = {0};
va_list arglist;
va_start(arglist, pszFormat);
_vstprintf_s(buf + _tcslen(buf), sizeof(buf) / sizeof(*buf), pszFormat, arglist);
va_end(arglist);
OutputDebugString(buf);
}

被折叠的 条评论
为什么被折叠?



