文章中的文字可能存在语法错误以及标点错误,请谅解;
如果在文章中发现代码错误或其它问题请告知,感谢!
#include <iostream> #include <array> int main() { std::array<int, 5> arr {1, 2, 3, 4, 5}; std::cout << "5th element is : " << arr[4] << std::endl; return 0; }
运行结果:
5th element is : 5
#include <iostream> #include <array> int main() { std::array<int, 5> arr {1, 2, 3, 4, 5}; std::cout << "5th element is : " << arr.at(4) << std::endl; return 0; }
运行结果:
5th element is : 5
#include <iostream> #include <array> int main() { std::array<int, 5> arr {1, 2, 3, 4, 5}; std::cout << "5th element is : " << std::get<4>(arr) << std::endl; return 0; }
运行结果:
5th element is : 5
以上。
参考文档:
1.https://www.cnblogs.com/jingyg/p/6774632.html
2.https://www.apiref.com/cpp-zh/cpp/container/array/get.html