目录
最近我用c++98随便写了一个程序,居然报错了
报错的程序:
#include<iostream>
#include<map>
using namespace std;
map<int,int> m;
int main()
{
m[1]=0;
m[5]=3;
for(auto it=m.begin();it!=m.end();it++)
{
cout<<it->first<<" "<<it->second;
}
return 0;
}
报错内容:
[Error] 'it' was not declared in this scope
[Error] 'it' does not name a type
[Error] expected ';' before 'it'
原因:
auto 需要c++11及以上版本编译器
修改:
1.修改编译器版本
点击 [工具-编译选项]
编译时加入以下命令:
-std=c++11
点击 [确定]
2.使用迭代器
map <int, int> iterator it;
总结:
c++ STL提供了非常全的数据类型,但我们需要好好利用它