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

后端 未结 5 683
后悔当初
后悔当初 2021-01-23 10:35

For example I have the following string,

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


        
5条回答
  •  甜味超标
    2021-01-23 11:08

    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

提交回复
热议问题