from string to a code

hi guys ..i wanna to know how can i get a string from the user and treat it as a c++ code ..is there any way to do that ??
Last edited on
1
2
std::string str;
std::cin >> str;
no .. that is not what i mean .. this code deal with the string as a string , not code ..

for example ,, if i have int a , b=1 , c=1
and the user type " a = b + c " as a string .. wanna the compiler deal with at as a code ..

cout >> a ;
output : 2
So you're going to write a command-line C++ interpreter? Good luck. Surely you don't intend to parse C++ code from the command line, but just a small set of operations? In that case you have to parse the text, look for the operator, then perform the operation yourself in your own code.
so there is no a direct way to do that in c++ ?? coz the problem is there might be a sin or cos or any other functions that i can not get it from the string .. the only way is to take the string as it is and little the compiler treat with it as a code (like google for drawing functions).
Use an interactive C++ interpreter for this? For instance, cling.
http://blog.coldflake.com/posts/2012-08-09-On-the-fly-C%2B%2B.html

Or maybe, just use python or haskell or any language that supports read-eval / read-exec loops.
seems not easy as i thought !
but thanks guys for ur help
Topic archived. No new replies allowed.