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 好听的元旦简短祝福语