[Error] ‘it‘ does not name a type

目录

报错的程序:

报错内容:

原因:

总结:


最近我用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提供了非常全的数据类型,但我们需要好好利用它

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值