为什么会出现错误:size不是std的成员
why is there an error: size is not a member of std?
#include <iostream> // for std::cout
#include <iterator> // for std::size
int main()
{
int array[] = { 1, 1, 2, 3, 5, 8, 13, 21 };
std::cout << "The array has: " << std::size(array) << " elementsn";
return 0;
}
当我运行这段代码时,我得到了类似size不是std成员的信息。任何评论都将不胜感激。
编译器不支持C++17,或者编译器选项没有激活这种支持
在任何情况下,您都可以使用标头<type-traits>
中声明的标准类模板std::extent
。例如
#include <iostream> // for std::cout
#include <type_traits> // for std::extent
int main()
{
int array[] = { 1, 1, 2, 3, 5, 8, 13, 21 };
std::cout << "The array has: " << std::extent<decltype( array )>::value << " elementsn";
return 0;
}
相关文章:
- 为什么我应该在异常处理中使用std::cerr而不是std::cout
- std::to_string - 'to_string' 不是 'std' 的成员 - Visual Studio Code 1.42.0
- FreeFileSync C++错误:'byte'不是 'std' 的成员
- 使用 std::addressof(std::cout) 而不是 &std::cout 是否有任何风险?
- 隐式转换为比较函数对象(函子)用于 std::sort 而不是 std::map?
- 无法从好友功能访问类的私有成员?"ostream"不是"std"的成员?
- 线程不是 std c++ 的成员
- 为什么会出现错误:size不是std的成员
- 读取互斥对象范围之外的volatile变量,而不是std::atomic
- 不是 'std::vector<_Ty> 的成员
- C++ GCC 错误:"sqrtl"不是"std"的成员
- _Pairib":不是"std::map,std::分配器"的成员>>
- 如何将 std::list of 派生类而不是 std::list of parent class 传递给函数
- 'make_unique'不是'std'的成员
- "random_shuffle":不是"std"错误的成员
- 为什么错误:"locate_zone"不是"std::chrono"的成员
- 为什么 std::when_any 使用 std::tuple 而不是 std::vector 作为其结果类型?
- "<某些系统标头>:错误:"<在此处插入函数>"在移动源文件后不是"std"的成员
- Clang希望我写:: STD :: Declval而不是STD :: Declval
- 哈希输出为 BYTE 而不是 std::string