怎么定义集合和枚举?

happyzsl 2002-11-05 07:39:39
想要定义一个由"100","103","895"等字符串组成的集合,并判断一个字符串如"100"是否在这个集合中
...全文
133 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
happyzsl 2002-11-06
  • 打赏
  • 举报
回复
枚举了?
我想根据输入字符串str:在指定集合中,根据名字不同调用不同函数,如果不在指定集合中的,都调用另一个函数
考虑用case,不过不知道怎么做
TopCat 2002-11-05
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main()
{
set<string> str_set;
str_set.insert(string("111"));
str_set.insert(string("222"));
str_set.insert(string("333"));

if (str_set.find(string("212")) != str_set.end())
{
cout << "元素在集合中" << endl;
}
else
{
cout << "元素不在集合中" << endl;
}

return 0;
}

13,873

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧