定义不定参数的函数的问题!!!
如何实现如printf("%d %s",10,"1000");的函数?
参数个数是不定的,参数类型也是不定的?不考虑重载
谢谢!!!
[解决办法]
...
A partial parameter list can be terminated by the ellipsis notation, a comma followed by three periods (, ...), to indicate that there may be more arguments passed to the function, but no more information is given about them.
[解决办法]
void MyPrint(char *format,...)
{
char szVarBuffer[VAR_STRING_BUFFER_SIZE];
va_list ar_ptr;
va_start(ar_ptr,format);
vsprintf(szVarBuffer,format,ar_ptr);
va_end(ar_ptr);
cout<<szVarBuffer<<endl;
}
[解决办法]
void Print(const char* pText, ...){ char buf[1024] = {0}; va_list va; va_start (va, pText); _vsnprintf(buf + strlen(buf), sizeof(buf) - 1, pText, va); va_end(va); printf(buf);}