I have a textbox & a list of strings (array). I am filtering the list using std::back_inserter
:
std::vector<string> upprCase;
....
std::remove_copy_if(
upprCase.begin(),
upprCase.end(),
std::back_inserter(filteredList),
std::not1(filter(str2)));
Using this, I am able to filter initial chars of the string, but how to filter string with chars at any place?
For example, if upprCase
is {abc,bcd,cde}
and str2=bc
(coming from textbox), I want filteredlist{abc,bcd}
// copies only the items where predicate returns 'false' ...
std::remove_copy_if(
upprCase.begin(),
upprCase.end(),
std::back_inserter(filteredList),
[&](const std::string &s){ return (s.find(str2) == std::string::npos); }
);
Or:
// copies only the items where predicate returns 'true' ...
std::copy_if(
upprCase.begin(),
upprCase.end(),
std::back_inserter(filteredList),
[&](const std::string &s){ return (s.find(str2) != std::string::npos); }
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.