在 Python 中,做 if a in b
真的很容易,我想知道 C++ 中是否有等价物。
具体来说,我想制作一个字符串列表并检查输入是否在该列表中。
std::string myinput;
std::string mylist[] = {"a", "b", "c"};
std::cin >> myinput;
// if myinput is included in mylist
// do other stuff here
如何使用 if
检查输入 myinput
是否包含在字符串 mylist
中?
原文由 Sumyjkl 发布,翻译遵循 CC BY-SA 4.0 许可协议
您也可以使用
std::count
如果数字
> 0
,则表示字符串在字符串中。