
Vue框架:从项目学Vue
OJ算法系列:神机百炼 - 算法详解
Linux操作系统:风后奇门 - linux
printf("%d %s %c %u", 1, "aaa", 'a', -1);
int main(int argc, char* argv[], char* envp[]){
/*
argc统计命令行参数个数
argv存储命令行参数,以nullptr结尾
envp存储环境变量,以nullptr结尾
*/
}
template <class ... Args> //定义可变参数模板
void ShowList(Args ... args){ //使用可变参数模板
//函数体
};
参数包内参数个数:
可以使用sizeof()获取参数包内参数个数
void ShowList(Args ... args){
for(size_t i=0; i<size_of...(Args); i++){
cout<<args[i]<<" ";
//报错:必须在上下文中扩展参数包
//主要原因是参数包内参数类太复杂
}
}
#include
#include
using namespace std;
template<class T>
void PrintArg(T t){
cout<<typeid(T).name()<<":"<<t<<endl;
}
template <class ...Args>
void ShowList(Args... args){
int arr[] = {(PrintArg(args), 0)...};
cout<<endl;
}
int main(){
cout<<"循环打印"<<endl;
ShowList(1, 'A', string("sort"));
return 0;
}
#include
#include
using namespace std;
template <class T>
void Show(T t){
cout<<typeid(T).name() <<":"<<t<<endl;
}
template <class T, class ... Args>
void Show(T t, Args ... args){
cout<<typeid(T).name() <<":" <<t<<endl;
Show(args...);
}
int main(){
cout<<"递归打印"<<endl;
Show(1);
Show(1, 'A');
Show(1, 'A', string("sort"));
return 0;
}