Is it possible to get the returned strings from an Exprtk expression? The code below returns NaN as answer, which is to be expected. But getting the string, in this case 'One', only seems possible using a return[] statement or by using an explicit string variable. But a simple std::string expression->value_() would be a great help. Stepping through the code shows a control_block_ with a string value_ private property with the correct result. But how is it accessible?
In the code there are two strings to evaluate, but both show the identical behavior.
Thanks for any thoughts. ...
#include "exprtk.hpp"
int main()
{
typedef exprtk::symbol_table<double> symbol_table_t;
typedef exprtk::expression<double> expression_t;
typedef exprtk::parser<double> parser_t;
const std::string expression_string =
//"if (1 > 0) {'One';} else {'Two';}";
"if (1 > 0,'One','Two')";
expression_t expression;
parser_t parser;
if (parser.compile(expression_string, expression))
{
double result = expression.value();
// How can the string result be retrieved at this point?
}
return 0;
}
...
I share how I solved it since the documentation was also quite confusing for me.
I use return in the expression for the return string, and then get the results of the expression.
Hope this helps someone, cheers!