void Printf(char*str...)
{
va_list list;
int intType;
char* charType;
float floatType;
char* curType = str;
va_start(list,str);
while( 0 != *curType)
{
switch(*curType)
{
case 'd':
intType = va_arg(list,int);
cout<<intType<<endl;
break;
case 'f':
floatType = va_arg(list,double);
cout<<floatType<<endl;
break;
}
curType++;
}
va_end(list);
}
本文介绍了一个使用C++实现的可变参数处理函数voidPrintf。该函数通过解析传入的字符串来确定如何处理后续的可变参数,支持处理整型(d)和浮点型(f)数据。
845

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



