目录
用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++98中遇到it未声明错误,原因是需要C++11及以上版本编译器。作者给出了升级编译器和使用迭代器的解决方案,强调了C++STL的合理利用。

被折叠的 条评论
为什么被折叠?



