c++ - Pass data as code -
i'm trying interpret formula given input:
y= y argv[1][s] 5;
where argv[1][s]
can + - *
example.
y= y+5;
y= y*5;
i use check specific values, it's more interesting find out why doesn't work.
error c2146: syntax error : missing ';' before identifier 'argv'
i think happens +
passed '+'
no operation results. there way unquote this?
no, because that's not how c++ works. code must make sense @ compile-time, compiler can convert fixed set of assembler instructions. run-time text not "substituted" in; there no equivalent of "eval" in interpreted languages.
if want this, you'll need like:
switch (argv[1][s]) { case '+': y = y + 5; break; case '-': y = y - 5; break; case '*': y = y * 5; break; default: std::cerr << "unrecognised operator: \"" << argv[1][s] << "\"" << std::endl; break; }
Comments
Post a Comment