1、auto、decltype
auto是C++11中的关键字,它可以通过类型推导自动得到变量或对象的类型,需要注意的是auto会忽略引用,因为引用其实就代表原对象:
#include <vector> #include "boost/assign.hpp" using namespace boost::assign; int main() { auto i = 10; auto f = 12.34; auto s = string("abc"); cout << i << ", " << f << ", " << s << endl; int num = i; double d = f; string str = s; vector<int> vc = list_of(1) (2) (3); auto iter = vc.begin(); auto iterEnd = vc.end(); for (; iter != iterEnd; iter++) { cout << *iter << endl; } return 0; }