【发布时间】:2013-01-30 23:04:28
【问题描述】:
编译错误说it没有在这个范围内声明,它没有命名类型,应该是;
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vec;
vec.push_back(1);
vec.push_back(3);
vec.push_back(5);
for (auto it = vec.begin(); it != vec.end(); ++it) {
cout << *it << endl;
}
cout << "size: " << vec.size() << endl;
return 0;
}
【问题讨论】:
-
工作正常:ideone.com/qVFl6p。你指定了 -std=c++11 吗?
-
是的,谢谢,我之前设置了它,但不能保存,但现在可以了!
-
您想修正缩进吗?
-
我是这样缩进的,因为我在发布代码时遇到了问题。
标签: c++ vector c++11 iterator auto