如何让std :: list <std :: string> :: iterator输出错误值?

cal*_*pto 2 c++ pointers iterator

我正在搜索值列表,并希望在找不到要搜索的值时让它返回某种"默认"错误值.我不是故意的std::cerr.我的意思是我可以在我的程序中使用的值,如bool.但是,如果它确实找到了字符串,我需要它在字符串中的指针值.我该怎么做呢?

Tim*_*Tim 5

typedef std::list<std::string> MyList;
MyList  mylist;
MyList::iterator iter = mylist.find("somestring");
if (iter != mylist.end() ) {
   // the string was found
} else {
   // the string was not found
}
Run Code Online (Sandbox Code Playgroud)