Thursday, July 30, 2009

Evaluation of mathematical expression in c++?

How do I evaluate a character string as a mathematical expression in c++. Are there any library functions or custom functions out there that can do this. I am currently running a program to write the expression to a header, including the header in another program and executing that program after the header has been modified. I am pretty sure there is a better way to do this (I do not want to check for conditions). Can the "system" command help here?

Evaluation of mathematical expression in c++?
Depending on the version of C++ you are using, there might be an eval() function. There is in Microsoft C++ / C#. It does exactly what you want: evaluates a string as C++ code.
Reply:There is a data structure you can use, it's called an expression tree. The nodes of the tree are the operators, and the leaves are the operands. It's a straightforward process to parse a string into an expression tree and solve it. Look for it on the net.
Reply:I don't completely understand your question, but maybe this is what you're looking for?





http://www.codeproject.com/cpp/FastMathP...


No comments:

Post a Comment