【发布时间】:2020-07-08 04:30:52
【问题描述】:
如您所见,我的代码运行良好,但我对在访问vector 时在第一个循环中使用auto 和int 存在疑问:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<vector<int>> a{{1,2,3},{4,5,6}};
//why don't work when i use int in the first loop,and why it work when i use auto
for(auto n:a)
{
for(int b:n)
{
cout<<b<<" ";
}
cout<<endl;
}
}
【问题讨论】:
-
auto from vector
被替换为 int 但来自 vector > cat 的 auto 被替换为 vector -
出于同样的原因
int x = a[0];是一个错误。