如何从地图访问数组的元素?
How to reach array's elements from map?
这是我的代码;
我有这样的地图和数组;
Array dayHours{0,0,0,0,0,0};
Array1 day{"Monday","Tuesday","Wednesday","Thursday","Friday"};
map<pair<string,int>,pair<Array1 ,Array> > matchMap;
我有一个这样的功能;
void Course::addCourse()
{
string a;
int b;
int total;
int courseAdd;
cout<<"How many course you want to add?"<<endl;
cin>>courseAdd;
cout<<"Enter the name of course and number of hours"<<endl;
for(int i=0;i<courseAdd;++i)
{
setCourseName(a);
setHours(b);
getCourseList().insert({a, b});
total += getHours();
matchMap.insert({make_pair(a,b),make_pair(day,dayHours)});
}
这是地图的打印功能:
void Course::seeMap()
{
map<pair<string,int>,pair<Array1 ,Array> >::iterator it;
for(it=matchMap.begin();it!=matchMap.end();++it)
{
for(int i=0;i<5;++i)
{
cout<<(it->first).first<<(it->first).second<<(it->second).first[i]<<endl;
}
}
}
这是我最后得到的:
How many course you want to add?
2
Enter the name of course and number of hours
Enter the course name
124124124
Enter the course hours
5
Enter the course name
12414124
Enter the course hours
6
You added the courses succesfully!
124124124--->5--->Monday
124124124--->5--->Tuesday
124124124--->5--->Wednesday
124124124--->5--->Thursday
124124124--->5--->Friday
12414124--->6--->Monday
12414124--->6--->Tuesday
12414124--->6--->Wednesday
12414124--->6--->Thursday
12414124--->6--->Friday
我需要的是这样的模板;
Coursename1 ---> Coursehour1 ---> Monday;
Coursename2 ---> Coursehour2 ---> Tuesday;
Coursename3 ---> Coursehour3 ----> wednesday;
.... 如何组织这样的模板的代码?
这是一个最小的例子,每个人都可以理解我得到什么。
How many course you want to add?
1
Enter the name of course and number of hours
Enter the course name
Coursenam1
Enter the course hours
4
You added the courses succesfully!
Coursenam1--->4--->Monday
Coursenam1--->4--->Tuesday
Coursenam1--->4--->Wednesday
Coursenam1--->4--->Thursday
Coursenam1--->4--->Friday
我像这样更改了代码;
for(int i=0;i<courseAdd;++i)
{
setCourseName(a);
setHours(b);
getCourseList().insert({a, b});
total += getHours();
matchMap.insert({make_pair(a,b),make_pair(day1[i],dayHours)});
}
void Course::seeMap()
{
map<pair<string,int>,pair<string ,Array> >::iterator it;
for(it = matchMap.begin();it!=matchMap.end();++it)
{
cout<<(it->first).first<<"--->"<<(it->first).second<<"--->"<<(it->second).first<<endl;
}
}
我得到了我想要的模板。
How many course you want to add?
2
Enter the name of course and number of hours
Enter the course name
214124124
Enter the course hours
4
Enter the course name
12512515
Enter the course hours
5
You added the courses succesfully!
12512515--->5--->Tuesday
214124124--->4--->Monday
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 使用strcpy将char数组的元素复制到另一个数组
- 如何将元素添加到数组的线程安全函数?
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 输出没有重复元素的动态数组(收缩数组)C++
- 数组中最大的非重复元素
- 数组元素打印的递归方法
- 对字符数组中的元素执行逐位操作
- 缓存std::数组的选定元素,并在c++中自动保持其一致性
- 如何计算数组中元素的位数?(不是数组的长度),并计算其数字的总和
- 通过交换元素使数组相同
- 按平均值替换数组中的元素
- 打印矢量数组中的所有元素
- 如何将字节数组元素替换为修改的十六进制 ASCII 符号?
- 如何为 c++ 的不同变量类型的结构元素创建动态数组?
- 如何将元素从向量转移到新数组?
- 如何在向量数组中插入元素?
- 为什么 2 个相同数组的元素彼此相等
- C++ 中的二维整数数组,每行中的元素数量不均匀