tableau non-string
#include<iostream>
using namespace std;
template<class T>
int length(T& arr)
{
return sizeof(arr) / sizeof(arr[0]);
}
int main()
{
int arr[] = { 1,5,9,10,9,2 };
// 方法一
cout << "数组的长度为:" << length(arr) << endl;
// 方法二
cout << "数组的长度为:" << end(arr)-begin(arr) << endl;
return 0;
}
Une méthode doit utiliser la fonction, sinon il est impossible de devenir un type int tableau [6] à partir int * Type.
Tableau de chaînes
tableau de chaînes, directement fonction strlen ().