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.
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP