【发布时间】:2017-12-01 04:31:09
【问题描述】:
我有一个包含 10000 个字符串的大向量:
std::vector<std::string> v;
for (int i = 0; i < 10000; i++) { v.push_back(generateRandomString(10)); }
我想显示包含“AB”作为子字符串的字符串。我试过了:
std::vector<std::string> res;
res = std::copy_if(v, [](auto s) { return s.find("AB") != std::string::npos; });
cout << res;
但我收到以下错误:
错误:没有匹配函数调用 'copy_if(std::vectorstd::__cxx11::basic_string
&, main(int, char**):: )' std::vectorstd::string b = std::copy_if(a, [](auto s) { return s.find("AB") != std::string::npos; });
如何过滤字符串向量并仅显示那些将“AB”作为子字符串的字符串?
(如果v 包含 50MB 的数据,这会有效吗?)
【问题讨论】:
-
或许值得一读the manual。
标签: c++ string algorithm vector filter