向量。检查它是否包含"Key" .C++
Vector. Checking to see if it contains "Key". C++
可能的重复项:
如何在 std::vector 中找到一个项目?
嘿,就像标题建议我想检查向量是否包含字符串"Key"。 我一直在谷歌上四处寻找,我在矢量库中找不到任何东西。 任何人都可以帮我解决这个问题。 提前谢谢。
您可以使用
std::find
。假设您有一个充满std::strings
的std::vector
:
#include <algorithm> // for std::find
std::vector<std::string> v = ....;
std::vector<std::string>::const_iterator it = std::find(v.begin(), v.end(), "Key");
bool found = it != v.end();
相关文章:
- 如果 KEY 是 std::list 或 std::vector 而不是值,那么 std::map 的默认行为是什么?
- 使用 Key 对 C++ 中的哈希映射进行排序. 无法排序
- std::<key-value>不同类型的对向量
- .value( "key" , default) 不适用于空的 json 对象吗?
- std::set<Key,Compare,Allocator>::find() 函数使用"<"运算符而不是"=="运算符背后的直觉是什么?
- std::move(key) 同时迭代unordered_map<字符串,字符串>?
- cpp / c ++中的grpc客户端代码,元数据x-api-key/x-goog-api-key不起作用,给了我语音A
- 黄金描述的C++ "Key Function"是什么?
- 从更新查询获取'Cannot insert duplicate key'
- 如何计算C++中非重复值的数量 std::map<Key,Values>
- SWIG:包装 std::map<key 时编译器错误,val *>
- getch() 函数在输入 key 时不执行任何操作
- 最适合"set with class member as key"的数据结构?
- 将"Enter Key"值分配给字符串 [C++]
- 这里不允许函数定义:void encryption(ifstream encrypt_file,ofstream key
- 使用 std::transform 将 std::vector<struct{key; val;}> 转换为 std::map<key, val>
- 使用 Visual Basic 更改C++中的"Press any key to Continue..."
- map(long long int,long long int)不适用于key=1000 000 000(在long l
- 如何在 C++ 中检测'Enter Key'?
- C++ 中 map_instance[key] 与 map_instance.find(key) 之间的区别