[try Beta version]
Not logged in

 
parsing string to double with stod()

Aug 10, 2018 at 3:32pm
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";
Aug 10, 2018 at 3:57pm
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().
Aug 10, 2018 at 4:05pm
Topic archived. No new replies allowed.