Here's before:
Code:
vector<map<std::string, int> > before;
Initialized with this function:
Code:
vector<map<std::string, int> > element::findelementplusgroupbefore(int* whereyield)
{
vector<map<std::string, int> > creed;
map<std::string, int> need;
std::string feed;
for (int i = 0; i < formula.size(); i++)
{
if (formula[i] == '+')
{
creed.push_back(need);
need.clear();
feed.clear();
}
else if (isupper(formula[i]))
{
if(islower(formula[i+1]))
{
if (isdigit(static_cast<int>(formula[i+2])))
{
feed += formula[i];
feed += formula[i+1];
need.insert(make_pair(feed, (static_cast<int>(formula[i+2])) - 48));
i += 2;
}
else
{
feed += formula[i];
feed += formula[i+1];
need.insert(make_pair(feed, 1));
i++;
}
}
else
{
if (isdigit(static_cast<int>(formula[i+1])))
{
feed += formula[i];
need.insert(make_pair(feed, (static_cast<int>(formula[i+1])) - 48));
i++;
}
else
{
feed += formula[i];
need.insert(make_pair(feed, 1));
}
}
feed.clear();
}
else if (formula[i] == '-' && formula[i+1] == '>')
{
*whereyield = (formula[i+1]) - 57;
break;
}
}
creed.push_back(need);
return creed;
}
And the constructor:
Code:
element::element()
{
cout << "Enter a formula:" << endl;
cin >> formula;
if (checkyield(formula))
{
before = findelementplusgroupbefore(&whereyield);
after = findelementplusgroupafter(whereyield);
printall();
}
}