Vivek Subramanian Vivek Subramanian - 1 year ago 47
C++ Question

Concise way to say equal to set of values in C++

For example I have the following string,

if (str[i] == '(' ||
str[i] == ')' ||
str[i] == '+' ||
str[i] == '-' ||
str[i] == '/' ||
str[i] == '*')

My question is there a concise way to say if this value one of these set of values in c++?

Answer Source

Not glorious because it is C instead of C++, but the C standard library is always accessible from C++ code, and my first idea as an old dinosaur would be:

if (strchr("()+-/*", str[i]) != NULL)

Simple and compact