I was trying to create a program to calculate the simplified version of a polynomial expression. I want to separate all of the variables, and constants (with plus signs) but my program seems to not be recognizing some of the plus signs in my string:
string al("2x+2+6y+8^7");
vector<string> variableStorage;
for (auto &c : al)
{
static int count = 0;
static int lastcount = 0;
if(c == '+' || count == al.length()-1)
{
static int spot(0);
variableStorage.push_back(al.substr(lastcount, count));
lastcount = count+1;
++spot;
}
++count;
}
for(auto c : variableStorage)
cout << c << endl;
When I run this program, I get the following output:
2x
2+6y
6y+8^7
8^7
But my desired output is:
2x
2
6y
8^7
I tried checking my math for any mistakes, but it seems good as far as I can see.