-
April 20th, 2007, 09:37 AM
#1
Converting a string into a line of code.
If I have a CString str; and say I have a function double y(double x). Suppose the string in str is "x*cos(x)", and I want the function double y(double x) to return what is written in str, is this at all feasible using MFC or any other standard utility libraries?
-
April 20th, 2007, 09:45 AM
#2
Re: Converting a string into a line of code.
You mean that you want 'y' to return a string instead of a double?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
April 20th, 2007, 10:41 AM
#3
Re: Converting a string into a line of code.
if i read you right you can simply let the y fn return a double and then convert the double into a CString:
z = y(x);
CSting str_of_z;
str_of_z.Format("%10.6f",z);
-
April 20th, 2007, 11:10 AM
#4
Re: Converting a string into a line of code.
Originally Posted by Fatboy
If I have a CString str; and say I have a function double y(double x). Suppose the string in str is "x*cos(x)", and I want the function double y(double x) to return what is written in str, is this at all feasible using MFC or any other standard utility libraries?
There is no standard tools for evaluating arithmetic expressions. Searching web, you can find some handy tools, examples, etc. Try googling for something like 'arithmetic expression parser' or something similar. However, thing I would recommend, is LUA interpreter. It is very handy, lightweight tool which may be used for parsing expressions. You might consider it too big to just parse expressions, but I think that its advantages are worth it: It supports variables, built-in basic math functions, custom functions, is portable (I compiled and used it on Windows and two Linux distros).
I tried also boost spirit library, but it is totally illegible for me
Cheers,
Hob
B+!
'There is no cat' - A. Einstein
Use [code] [/code] tags!
Did YOU share your photo with us at CG Members photo gallery ?
-
April 23rd, 2007, 05:12 AM
#5
Re: Converting a string into a line of code.
Hahaha,
That's funny, only Hobson understood Fatboy's question.
Fatboy would like to create an application something similar like Matlab (but I guess a very small one).
Peace!
-
April 23rd, 2007, 06:16 AM
#6
Re: Converting a string into a line of code.
Yes, a very very small Matlab, or you can view it as a something more than a graphic calculator. Thanks guys for your help, and respect to Hobson for understanding my question, I know it was hard to decipher!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|