rah*_*hul 4 c++ visual-c++ c++11
我对c ++很新,有没有一种方法在c ++中我们可以通过for循环迭代除了整个静态数组?
int arra[10] = {1,2,3,4};
std::cout << arra << std::endl;
Run Code Online (Sandbox Code Playgroud)
我试过这个,但这是打印数组中第一个元素的地址.
以下不使用循环:
std::copy(std::begin(arra),
std::end(arra),
std::ostream_iterator<int>(std::cout, "\n"));
Run Code Online (Sandbox Code Playgroud)
但循环似乎更容易读/写/理解:
for (const auto& e : arra) {
std::cout << e << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
23511 次 |
最近记录: |