如何在C ++中打印多维数组的维
这是一个C++程序,用于打印给定数组的维数。
算法
Here template() function is used to find out the current size of array. Then recursively call it till the last dimension of array.
范例程式码
#include <iostream>
using namespace std;
template <typename t, size_t n>
void printDimensionsOfArray(const t (&a)[n]) {
cout << n;
}
template <typename t, size_t n, size_t m>
void printDimensionsOfArray(const t (&a)[n][m]) {
cout << "Dimensions of the Array is: "<<n << " x ";
printDimensionsOfArray(a[0]);
}
int main() {
int a[6][7];
printDimensionsOfArray(a);
return 0;
}输出结果
Dimensions of the Array is: 6 x 7
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短