MCPcopy Create free account
hub / github.com/changkun/modern-cpp-tutorial / main

Function main

code/2/2.4.cpp:12–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <vector>
11
12int 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected