如果存在字符串,则设置bool值

Setting a bool if a string is present

本文关键字:设置 bool 存在 字符串 如果      更新时间:2023-10-16

我需要根据数据字典中是否存在字符串设置一个布尔值,其结构为:

std::map< string, foo > dd

如果我要找的字符串在那里,那么布尔值为真,反之亦然。有人能帮助我如何在c++中做到这一点吗?

谢谢。

假设数据字典为std::map<String,> dict;

bool const word_present( string str_word, std::map< string, foo > &dict)
{
    return (dict.find( str_word ) != dict.end());
}