| 10 | #include <vector> |
| 11 | |
| 12 | int main() { |
| 13 | int array[] = {1,2,3,4,5}; |
| 14 | for(auto &x : array) { |
| 15 | std::cout << x << std::endl; |
| 16 | } |
| 17 | |
| 18 | // 传统 C++ 写法 |
| 19 | std::vector<int> arr(5, 100); |
| 20 | for(std::vector<int>::iterator i = arr.begin(); i != arr.end(); ++i) { |
| 21 | std::cout << *i << std::endl; |
| 22 | } |
| 23 | |
| 24 | // C++11 写法 |
| 25 | // & 启用了引用, 如果没有则对 arr 中的元素只能读取不能修改 |
| 26 | for(auto &i : arr) { |
| 27 | std::cout << i << std::endl; |
| 28 | } |
| 29 | return 0; |
| 30 | } |
nothing calls this directly
no outgoing calls
no test coverage detected