Let me explain what I want to do:
I want to change a expression like this: x * (2 + 3) - (y + 1)
to this: 5 * (2 + 3) - (6 + 1)
using this:
instVar('x', 5);
instVar('y', 6);
The problem is I get the following output:
5 * (2 + 3) - (y + 1)
x * (2 + 3) - (6 + 1)
Here is my code:
size_t pos = 0;
while ((pos = originalExpr.find(var, pos)) != std::string::npos)
{
modifiedExpr = originalExpr;
char a_val = '0' + val;
std::replace( modifiedExpr.begin(), modifiedExpr.end(), var, a_val);
pos++;
}
//Testing the output if it works
cout << modifiedExpr << endl;
How can I change it so that the output can give me this:
5 * (2 + 3) - (y + 1)
5 * (2 + 3) - (6 + 1)