C++ std::array::size 返回模板参数 N,编译期可知,也可当作运行期 size_t 使用。
原型
constexpr size_t size() const noexcept;参数
- 无参数。
返回值
元素个数,等于 N。
示例
#include <array>
#include <iostream>
int main() {
std::array<int, 3> a{1, 2, 3};
std::cout << a.size() << "\n";
return 0;
}输出:
3
注意事项
与内置数组不同,作为函数参数传递时不会退化成指针,长度仍在类型里。
下一页介绍at。