#include #include #include #include #include using namespace std; std::function getquery() { cout << "full string?"; string yn; cin >> yn; if (yn.find("y")!=string::npos || yn.find("Y")!=string::npos) { cout << "word to find: "; string query; cin >> query; return {[query](const string s) { return s==query; }}; } else { cout << "prefix to find: "; string query; cin >> query; cout << "min length: "; int minlen; cin >> minlen; return {[query,minlen](const string s) { return s.length()>=minlen && s.find(query)==0; }}; } } int main(int argc, char **argv) { ifstream f("words"); vector words; while(!f.eof()) { string w; f >> w; words.push_back(w); } /* cout << "word to find: "; string query; cin >> query; auto loc = find_if(begin(words),end(words), [query](const string s) { return s==query; } ); */ /* cout << "prefix to find: "; string query; cin >> query; cout << "min length: "; int minlen; cin >> minlen; */ /* auto loc = find_if(begin(words),end(words), [query,minlen](const string s)->bool { return s.length()>=minlen && s.find(query)==0; } ); */ /* auto loc = find_if(begin(words),end(words), [=](const string s)->bool { return s.length()>=minlen && s.find(query)==0; } ); */ auto myquery = getquery(); auto loc = find_if(begin(words),end(words),myquery); if (loc==words.end()) cout << "not found" << endl; else { cout << "found: " << *loc << endl; int num = count_if(begin(words),end(words),myquery); cout << "(" << num << " total matches)" << endl; } }