C++11中常用的几个简写

C++11添加了很多新特性,可以使程序代码变得简洁,这些特性实用而且效率高。

不便之处是:要增加学习成本,还有你要升级你的编译器了。

目前支持C++11特性的编译器有:

  • g++ 4.8
  • clang 3.3
  • intel 13.0
  • vs2012 nov ctp

目前刚接触,看看下面几个常用C++11的代码:

(1)比如:

vector<vector<MyType>>::const_iterator it = v.begin() 

可以简写为:

auto it = v.cbegin() 


(2)遍历数组,遍历字符串,遍历STL容器,遍历STL  map

比如不知道数组容器的大小,即可方便的遍历数组:

int arr[] = {1, 2, 3, 4};  
for(auto i : arr) {  
    std::cout<< i << std::endl;  
} 

 

 

posted @ 2014-06-16 23:08  Xylophone  Views(421)  Comments(0Edit  收藏  举报