c++ vector中没有类似count contain方法
但是,使用algorithm中的count就可以了
vector<int> res = {1,2,3};
int key = 2;
if(count(res.begin(),res.end(),key){
cout<<"exist"<<endl;
}else{
cout<<"no"<<endl;
}
count函数是algorithm中的,判断list也同理吧!
本文介绍如何使用C++标准库中的count函数来检查vector容器内是否存在特定元素。通过实例演示了如何利用algorithm头文件中的count函数实现类似countcontain的功能。
c++ vector中没有类似count contain方法
但是,使用algorithm中的count就可以了
vector<int> res = {1,2,3};
int key = 2;
if(count(res.begin(),res.end(),key){
cout<<"exist"<<endl;
}else{
cout<<"no"<<endl;
}
count函数是algorithm中的,判断list也同理吧!

被折叠的 条评论
为什么被折叠?