#include<map>
#include <iostream>
using namespace std;
void printMap(map<int,Person>&m) {
for (map<int, Person>::iterator it = m.begin(); it != m.end(); it++) {
cout << "key = " << it->first << " Person value 姓名:" << it->second.m_Name << "Person value 年龄:" << it->second.m_Age << endl;
}
}
class Person {
public:
Person(string name, int age) {
this->m_Name = name;
this->m_Age = age;
}
string m_Name;
int m_Age;
};
void test01() {
map<int, Person>m;
Person p1("刘备", 20);
Person p2("张飞", 21);
Person p3("关羽", 25);
Person p4("赵云", 26);
m.insert(make_pair(1, p1));
}
int main()
{
test01();
system("pause");
return 0;
}
C++STL map容器这样的写法为啥报错
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- _花花 2021-02-03 18:16关注
1,#include<string>
2,class Person定义放到void printMap(map<int,Person>&m) 前
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!
- ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
- ¥15 求daily translation(DT)偏差订正方法的代码
- ¥15 js调用html页面需要隐藏某个按钮
- ¥15 ads仿真结果在圆图上是怎么读数的
- ¥20 Cotex M3的调试和程序执行方式是什么样的?