新人求助有关于cpp中map的问题
  • 板块学术版
  • 楼主Fionn_Lee
  • 当前回复5
  • 已保存回复5
  • 发布时间2022/10/27 17:45
  • 上次更新2023/10/27 05:35:56
查看原帖
新人求助有关于cpp中map的问题
834727
Fionn_Lee楼主2022/10/27 17:45
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	map<int,string>student;//也可以倒着来,key(键)value(值)
	student[1]="student_one";
	student[2]="student_two";
	student[4]="student_four";
	map<int,string>::iterator it;
	int a=student.count(2);//查找是否有2,1真0假 
	map<int,string>::iterator b;
	b=student.find(4);//返回4 
	cout<<a<<" "<<b->first<<endl;
	//erase insert等都是基于key(键),也有empty clear 
    就是->first那里,我想知道当key为4的时候的位置,就是想输出3,第三个位置嘛,但是却输出4了。。。求问大佬们怎么改
	for(it=student.begin();it!=student.end();it++)
	{
		cout<<it->first<<" "<<it->second<<endl;//first second 
	}
	return 0;
} 
2022/10/27 17:45
加载中...