parsing string to double with stod()

Hello, I would like to know how to use the function stod() with string expressions that have variables inside the string. When the string has variables (for example, X) in it to which I will assign a double value. For example, how the following expressions could be converted to double with stod():

1
2
3
4
  double X = 1.0;
  string mystring1= "1.0*X*X";
  string mystring2= "X+1.0";
  string mystring3= "sin(1.0)/X";
I would like to know how to use the function stod() with string expressions that have variables inside the string.


You can't. You would have to parse the string and calculate the value by substituing the variables and carrying out the appropriate operations, and by that point you've already got the number and you no longer need stod().
Topic archived. No new replies allowed.