Click here to Skip to main content
15,916,692 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello everyone, I'm writing a C++ application.
In my application I must load a formule typied by the user from a text file.
The formule can be ((WIDHT+5)*5/2)-(LARG/2). The problem is that that formule is a string and I've found how I can evaluate it as a double. Knowing that WIDTH and LARG are constant.
Thanks for your precious help
Best regards.
Posted

If you need to evaluate expressions, then you may consider to embed a scripting launguage (e.g. Lua, see, for instance [^]) in you application.
:)
 
Share this answer
 
v2
What you need is code to evaluate an expression; there are several good articles on the subject here at CodeProject, e.g. State of the Art Expression Evaluation[^]

:)
 
Share this answer
 
You may use Boost Spirit [^].
For your simple case adapting the calc5 sample [^] to add some constants should not be too difficult.
cheers,
AR
 
Share this answer
 
Thank you all for your helpful responses. I've found Expression evaluator : using RPN[^]
It's useful and simple.
Thanks again.
Best regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900