标签:%s ntp lis div nbsp 实践 start hid put
参考1:https://www.cnblogs.com/edver/p/8419807.html
参考2:https://blog.csdn.net/iynu17/article/details/51588199
参考3: https://www.cnblogs.com/fanzhidongyzby/p/3519838.html
#include <iostream> #include <stdarg.h> #include <stdio.h> using namespace std; //============================================================================ //总结: //============================================================================ void fun(int paramCount, ...){ cout<<"参数个数:"<<paramCount<<endl; va_list params; va_start(params, paramCount); while(paramCount--){ char* strParam = va_arg(params, char*); int intParam = va_arg(params, int); cout<< strParam << endl; cout<< intParam << endl; } va_end(params); } void print11(const char *format, ...) { va_list arg; va_start(arg, format); while (*format) { char ret = *format; if (ret == ‘%‘) { switch (*++format) { case ‘c‘: { char ch = va_arg(arg, char); putchar(ch); break; } case ‘s‘: { char *pc = va_arg(arg, char *); while (*pc) { putchar(*pc); pc++; } break; } default: break; } } else { putchar(*format); } format++; } va_end(arg); } int main(){ cout << "函数可变参数实践:" << endl; // 2指2对参数 fun(2,"Welcome1:",1,"Welcome2:",2); print11("%s %s %c%c%c%c%c!\n", "welcome", "to", ‘C‘, ‘h‘, ‘i‘, ‘n‘, ‘a‘); cout << "end." << endl; return 0; }
问题:
标签:%s ntp lis div nbsp 实践 start hid put
原文地址:https://www.cnblogs.com/do-your-best/p/11110959.html