如何在C ++中的向量中找到子字符串

gra*_*eza -3 c++ string vector

我想知道如何查找子字符串在包含行(字符串组)的向量中出现的次数。

And*_* DM 6

您可以使用 std::count_if

std::vector<std::string> v { "this is a line", "foo", "This is another line" };

auto count = std::count_if(std::begin(v), std::end(v), [](auto const& s) {
  return s.find("line") != std::string::npos;
});

std::cout << count;
Run Code Online (Sandbox Code Playgroud)