How can i evaluate string expression in if statement?
-
I want to evaluate string expression in if stmt. E.g. int i = 0,j = 2; char * str = "(i == 0) || (j == 2)"; if(str) /* This should execute code within if condition*/ { ... }
-
Answer:
You will need to write a mini parse to recognize and evaluate the sequence of characters in the string as an expression belonging to some grammar. Perhaps use a parser library to do this; for example Spirit which is part of Boost. http://www.boost.org/doc/libs/1_37_0/libs/spirit/classic/index.html
Miningco.com Visit the source
Related Q & A:
- How can I echo characters before and after a string?Best solution by stackoverflow.com
- How can I convert a string number to a number in Perl?Best solution by Stack Overflow
- How can I find an online job that I can start for free?Best solution by Yahoo! Answers
- How can I make my personal statement great?Best solution by shmoop.com
- How can i do a statement?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.