#include<iostream>
using namespace std;
template <class t>
t foreach(t* p)
{
int i=0;
while(*p!='/0')
{cout<<*p<<endl;
p++;
i++;
}
cout<<"arry length is:"<< i<<endl;
return 0;
}
int main()
{
char a[]="1254638";
foreach(a);
getchar();
return 0;
}
本文展示了一个使用C++模板函数来遍历并打印字符数组元素的示例,同时计算并输出了数组长度。该示例有助于理解如何在C++中运用模板进行数组操作。
1万+

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



