我最近主要只处理 Python 编程,它们是一个非常有用的内置函数,称为“'in'
'in' 允许您访问变量中的所有元素。
例如;
def main():
y = ["Yes", "yes", "YES",]
n = ["No", "no", "NO"]
print "yes or no?\n"
response = raw_input()
if response in y:
print "Wonderful, your response was ", response, "\n"
exit(0)
if response in n:
print "Alas, your response was ", response, "\n"
exit(0)
else:
print "Message not read; please attempt again.\n"
main()
main()
如您所见,它使用“in”函数来检查字典中的字符串。
我想知道标准 C++ 库中是否有与此功能等效的功能?