表示等于C ++中的一组值的简洁方法 [英] Concise way to say equal to set of values in C++

查看:45
本文介绍了表示等于C ++中的一组值的简洁方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有以下字符串,

For example I have the following string,

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

我的问题是有一种简洁的方法来说明此值是否是c ++中的一组值吗?

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

推荐答案

不光彩,因为它是C而不是C ++,但是C标准库始终可以从C ++代码访问,而我作为旧恐龙的第一个想法是:

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)

简单而紧凑

这篇关于表示等于C ++中的一组值的简洁方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆