C++11 新特性
2016-09-22 10:25
267 查看
【1】新关键字 auto
作用:自动类型推导
【2】序列for循环
作用:用于遍历数组,容器等
【3】初始化方法
作用:自动类型推导
auto a////auto是通过初始化表达式进行类型推导,如果没有初始化表达式,就无法确定a的类型 auto i=1; auto d=1.0; auto str="hello world"; auto ch='A'; auto ite=iv.begin(); auto p=new foo()//自定义类型推导
【2】序列for循环
作用:用于遍历数组,容器等
void ShowVec(const vector<int>& valList) { for (auto iter = valList.cbegin(); iter != valList.cend(); iter++) { cout << (*iter) << endl; } } void ShowVec(const vector<int>& valList) { for (auto val : valList) { cout << val << endl; } }
【3】初始化方法
//支持如下方式的初始化方法 int arr[3]{1, 2, 3}; vector<int> iv{1, 2, 3}; map<int, string>{{1, "a"}, {2, "b"}}; string str{"Hello World"};
相关文章推荐
- C++11 新特性:Lambda 表达式
- C++11新特性,实现用字符串作为switch的case子句
- 【C++11】新特性——auto的使用
- C++11 常用特性
- C++11新特性:Lambda函数(匿名函数) 一段代码即可理解
- C++开发者都应该使用的10个C++11特性
- C++11新特性(持续更新)
- C++11特性(7):auto、decltype(自匹配类型)
- 一个实例介绍C++复制控制(有一个C++11新特性要注意)——复制构造函数、赋值操作符、析构函数
- C++11新特性应用--介绍几个新增的便利算法(关于最大值和最小值的算法)
- C++11新特性
- 【C++】C++11特性:初始化、hash容器和随机数生成器
- c++11新特性的简单介绍
- 在C++98基础上学习C++11新特性
- C++培训 C++11新特性:杂项
- [C++11新特性]第二篇
- C++11新特性总结(枚举+继承+左右值引用+变长模板)
- C++11新特性:Lambda函数(匿名函数)
- 使用eclipse编译含有C++11特性的代码
- 30分钟了解C++11新特性