map<int,list<string>>::iterator i = m.begin(); auto i = m.begin(); // 就是如此简单……
#include<deque> usingnamespacestd;
intmain() { deque<double> dqDoubleData(10, 0.1); for (auto iter = dqDoubleData.begin(); iter != dqDoubleData.end(); ++iter) // 注意是 ++iter { /* ... */ } for (auto elem : dqDoubleData) { /* ... */ } for (auto& elem : dqDoubleData) { /* ... */ } for (constauto& elem : dqDoubleData) { /* ... */ } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
double x = 12.34; auto *y = newauto(x), **z = newauto(&x);
auto x = 1, *y = &x, **z = &y; // Resolves to int. auto a(2.01), *b (&a); // Resolves to double. auto c = 'a', *d(&c); // Resolves to char. auto m = 1, &n = m; // Resolves to int.
intf(int x){ return x; } intmain() { auto x = f(0); // int x constauto & y = f(1); // const int & y 引用 int (*p)(int x); p = f; auto fp = p; // 返回值为 int 类型的函数的指针 }