How to work with a string to evaluate numbers coming into a condition?
string = "(t>=2 && t<5) || (t<1)";
int c = 0;
for(int t = 0; t < 10; t++){
if( {string} )
c++;
}
How to work with a string to evaluate numbers coming into a condition?
string = "(t>=2 && t<5) || (t<1)";
int c = 0;
for(int t = 0; t < 10; t++){
if( {string} )
c++;
}
If it's about Qt I would write something like
QScriptEngine e;
e.globalObject().setProperty("t", 123);
bool result = e.evaluate("(t>=2 && t<5) || (t<1)").toBool();
if you want an embedded scripting language (you havent given us the broader context of what you are trying to do) then there are several you can try. Lua is very c friendly (I have used it and it was fine) google's V8 javascript engine is supposed to be very good in c++ (I have not tried it). You can embed python too but many people don't like its syntax
You cannot do that in C++ as far as I know.