How to Find a Substring in a Particular String in a Set

倾然丶 夕夏残阳落幕 提交于 2020-02-08 10:03:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!