【发布时间】:2019-08-15 16:54:49
【问题描述】:
我有一个结构列表,如下所述:
struct Files
{
string id;
string path;
string chksum;
};
还有一个包含此结构列表的变量,该结构描述了一个文件列表,其中包含字段id、path 和chksum。
list<Files> myFiles;
我需要实现一个函数来搜索我的列表中是否存在确定的文件名。
我尝试使用find_if 算法,但遇到了非常奇怪的错误,我不确定如何有效地实现。
string filename = "mytext.txt";
auto match = std::find_if(myFiles.cbegin(), myFiles.cend(), [] (const Files& s) {
return s.path == filename;
});
if (match != myFiles.cend())
{
cout << "omg my file was found!!! :D";
}
else
{
cout << "your file is not here :(";
}
【问题讨论】:
-
我尝试使用
find_if...您也可以添加该代码吗? -
当然...我编辑以包含我尝试过的代码
-
为了将来参考,请尝试在您的问题中包含尽可能多的细节:您使用的是什么 IDE?您收到的错误文本是什么?等
-
奇怪的错误不能很好地描述问题。
标签: c++ algorithm struct lambda find