+ 1
Evaluating math inside of a string C++
I'm working on something and I'm wondering if I have a string "2+2" or "pow(2,5)" (and I have included math.h), is there is any direct to convert that into 4 and 32 respectively? I can convert "4" into a double but it won't work with operators. If there isn't any direct way, I have a work-around but it'll be a pain to implement so I'd rather not if I don't have to.
3 Respostas
+ 2
No. You have to parse the string.
+ 2
I looked into this for you and 1of3 is correct. The only way is possible by embedding another scripting language like Lua or Java.Which would then let you execute the strings code.
+ 1
Okay, that's what I was afraid of lol but ty for the answer