Vivek Subramanian Vivek Subramanian - 2 months ago 7
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

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

Comments