I am running a simple program:
#include<iostream>
#include<math.h>
using namespace std;
double fu (double x) {
double func = pow(x,0.5);
return func;
}
int main (int argc, char* argv[]) {
double x = 2;
double func = fu(x);
cout<<"f(x) = "<<func<<endl;
return 0;
}
Here func
is a function of which value is calculated at x
.
Suppose, I need to use this program from another program or if I want to give a function, such as pow(x,0.5)
or sqrt(1+sin(x))
during command line running of this program.
How I can do that? If I do it using argv
, then can you suggest how can I convert a string into an expression func
(that can be evaluated by C++ compiler)?
Any suggestions?