why is there an error: size is not a member of 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) << " elements\n";
return 0;
}
当我 运行 这段代码时,我得到类似 size is not member of std 的东西。非常感谢任何意见。
您的编译器不支持 C++ 17,或者编译器选项未激活此类支持
在任何情况下,您都可以使用在 header <type-traits>
中声明的标准 class 模板 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 << " elements\n";
return 0;
}
#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) << " elements\n";
return 0;
}
当我 运行 这段代码时,我得到类似 size is not member of std 的东西。非常感谢任何意见。
您的编译器不支持 C++ 17,或者编译器选项未激活此类支持
在任何情况下,您都可以使用在 header <type-traits>
中声明的标准 class 模板 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 << " elements\n";
return 0;
}