C ++中的类型推断
类型推断或推论是指以编程语言自动检测表达式的数据类型。它是某些强静态类型的语言中提供的功能。在C++中,auto关键字(在C++11中添加)用于自动类型推导。例如,您想创建一个迭代器来迭代向量,则可以简单地使用auto来实现此目的。
示例
#include<iostream>
#include<vector>
using namespace std;
int main() {
vector<int> arr(10);
for(auto it = arr.begin(); it != arr.end(); it ++) {
cin >> *it;
}
return 0;
}输出结果
In the above program, it will automatically get the type std:: vector<int>:: iterator.
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短