0
我的要求是计算字符串向量内字符串出现次数。要搜索的字符串位于矢量的第0个索引处。计算字符串向量中字符串出现次数
我使用内置的count
功能从algorithm
头,但得到一个奇怪的编译错误,我无法解决。
我的代码:
vector<string> a={"abc", "def", "abc"};
int cnt = count(a.begin(), a.end(), a[0]);
编译错误信息是:
count(std::vector<std::basic_string<char> >)':
error: no matching function for call to std::vector<std::basic_string<char> >::iterator, std::vector<std::basic_string<char> >::iterator, __gnu_cxx::__alloc_traits<std::allocator<std::basic_string<char> > >::value_type&)'
int cnt = count(a.begin(), a.end(), a[0]);
任何帮助吗?这里有什么问题?
[无法复制]我的解决方案可能是有用的( http://coliru.stacked-crooked.com/a/5192baa686d1f63a)。请发布[mcve]。 –
你是否错过了包含'std :: vector'? –
包含'std :: vector'。 – mtk