Hi. I encountered a problem here. I'm using C++ multiset. This is the test file.
Score: 3-1
Ben
Steven
Score: 1-0
Ben
Score: 0-0
Score: 1-1
Cole
Score: 1-2
Ben
I'm using while loop and ifstream (fin1) to read in from the test file above.
multiset<string, less<string> > myset;
while(!fin1.eof())
{
fin1 >> scoreName;
if(scoreName == "Score:")
{
//calculates number of matches played
}
else
{
goalCheck = scoreName.substr(1,1);
if(goalCheck == "-")
{
string lGoal, rGoal;
lGoal = scoreName.substr(0,1);
rGoal = scoreName.substr(2,1);
int leftGoal, rightGoal;
leftGoal = atoi(lGoal.c_str());
rightGoal = atoi(rGoal.c_str());
if(leftGoal > rightGoal) //if team wins
{
//some computations
}
else if(leftGoal < rightGoal) //if team loses
{
//computations
}
else if(leftGoal == rightGoal) //if team draws
{
//computations
}
else
{
myset.insert(myset.begin(), scoreName);
}
}
}
I'm inserting all names into myset (regardless of wins/loses/draws) in my last else statement. But I only require the names of those matches who won/draw.
Those names whose matches lost will not be included in myset. In the test file above, there's only one match that lost (1-2) and I wanted to remove "Ben". How can I do that?
I tried to use myset.erase(), but I'm not sure how to get it point to Ben and remove it from myset.
Any help is much appreciated.
Thanks.