Simply link libUb3rMath.a in your project, and include libUb3rMath.h, then you can use Ub3rMath to parse strings as equations.
Note: For versions below 1.4, the --std=c++0x flag is needed to compile.
Here is a simple example which takes an equation from the command line and prints out the answer:
#include "libUb3rMath.h"
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
Ub3rMath engineMain; //Initialize the engine
engineMain.SetMode(MODE_DEGREES | MODE_LEFTAPP); //Set the mode flags
//Make sure an equation was specified
if (argc != 2)
{
cout << "Usage: Ub3rMath_test <equation>" << endl;
return 1;
}
string solution = engineMain.Solve(argv[1]); //Get the answer
if (engineMain.LastError() == EQUATION_VALID) //Make sure the equation was valid
{
cout << solution << endl;
}
else
{
//Something went wrong. Print the error
cout << "Error #" << engineMain.LastError() << ": " << engineMain.LastErrorMessage();
}
return 0;
}
[Compiling the library]
[Using the library in projects]
[Features and components]
[Defined Symbols]
[Equation examples]
[Projects that use Ub3rMath]
Wiki: Compiling the library
Wiki: Defined Symbols
Wiki: Equation examples
Wiki: Features and components
Wiki: Home
Wiki: Projects that use Ub3rMath
Wiki: Using the library in projects