问题
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)
回答1:
You are likely looking for
if (search.find(str) != std::string::npos)
The std::find
call you have shouldn't compile.
来源:https://stackoverflow.com/questions/59923926/how-to-find-a-substring-in-a-particular-string-in-a-set