I have data in a particular format and I want to store them through vectors/pairs/maps in c++.
eg:
Group A Group B Group C ........
John Matt Shawn
Jane Liam Tom
.
.
.
There can be any number of groups and any number of names in them (all strings).
I expect as groups to be formed (which can be any in number) with any number of names in them. So I tried declaring them as a map or a pair.
The above format is what I want to store.
I tried doing it in this form:
Map<vector<int>, vector<string> > groups;
groups[i] = names.at(i);
Doesnt work.
The code of the method is:-
void form_groups(vector<string> teams){
pair<vector<int>, vector<string> > groups;
int num_teams_in_grp = 0;
int group_num = 1;
int i = 0;
while( i < teams.size())
{
groups[group_num] = teams.at(i++);
num_teams_in_grp++;
}
group_num++;
}
You have been vague with your format so I’ll make the following assumption. You have some number of group names, and some number of groups, each group being defined as a set of members.
I recommend storing them like this:
To add people to a group, using your specific data format, which I assume to be:
You would have to keep track of the indices of each group name so you could keep track of which group you were supposed to be adding members to, by line. For that purpose you might use something like the following C++ like pseudocode: