Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
Hi guys,
I have a string such as "x = 1, y = 2", and then I want to calculate the result of string "x + y" or "x * y", does any library can implement what I want???
Thanks very much!
Posted

Nope. You may find an API but I'd write one myself.

Look at the below example of how to parse arithmetic strings using stacked operators

There may be a API you can pull out of it:
Math Parser .NET C#[^]
 
Share this answer
 
This has nothing to do with math. Consequently you don't need a math library, but an expression parser: https://www.google.ch/search?q=experession+parser&ie=utf-8&oe=utf-8&gws_rd=cr&ei=D4J5VZmaHoKQsAGDh6eYBw#q=expression+parser+C%2B%2B[^]

The first hit on that search already looks promising. https://fastmathparser.codeplex.com/[^]

P.S.:
There are also suitable hits on this site:
Fast Mathematical Expressions Parser[^]
CalcStar: A C++ Math Expression Evaluator[^]
 
Share this answer
 
v2

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