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

后端 未结 5 622
后悔当初
后悔当初 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:19

    You may use the following:

    const char s[] = "()+-/*";
    
    if (std::any_of(std::begin(s), std::end(s), [&](char c){ return c == str[i]})) {
         // ...
    }
    

提交回复
热议问题