本文介绍了是否有更短的方法来编写复合“if"条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是代替:
if ( ch == 'A' || ch == 'B' || ch == 'C' || .....
例如,做喜欢:
if ( ch == 'A', 'B', 'C', ...
是否有一种更短的方法来总结条件?
is there even a shorter way to summarize conditions?
推荐答案
strchr()
可用于查看字符是否在列表中.
strchr()
can be used to see if the character is in a list.
const char* list = "ABCXZ";
if (strchr(list, ch)) {
// 'ch' is 'A', 'B', 'C', 'X', or 'Z'
}
这篇关于是否有更短的方法来编写复合“if"条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!