How do you find the substring within a string in a set? For example, if I enter "Ville," then Louisville, Gainesville, and Muellerville are found? I have tried the following code
for(string const& search : cities) { if(find(search.begin(), search.end(), str) != std::string::npos) { string y = search; employees.emplace_back(y); ,but I cannot figure out what is wrong with my syntax. This code is used in the following project (Project Code)
EDIT: My problem was simple and was fixed with using .begin() and .end() to iterate over the multimap name_address and finding each name with .substr. I also used a multimap instead of a set. I found the syntax easier and got it to work.
for(auto it = name_address.begin(); it != name_address.end(); ++it) { for(int i = 0; i < it->first.length(); ++i) { string tmpstr3 = it->first.substr(0 + i, str.length()); if(str == tmpstr3) { employees.insert(it->second); break; } } }
std::search? Because this is not whatstd::findis for.