【发布时间】:2016-08-23 05:39:30
【问题描述】:
我将 StringVec 定义为:
typedef std::vector<string> StringVec;
变量 colnames 定义为:
StringVec colnames;
我有一个功能如下:
int colIndex(const string &cn) const {
StringVec::iterator i1;
i1 = find(colnames.begin(),colnames.end(),cn);
return(i1 == colnames.end() ? -1 : (i1 - colnames.begin()));
}
当我尝试使用 GNU g++ 4.9.2 (C++11) 编译时,它会抱怨:
error: no matching function for call to 'find(std::vector<std::basic_string<char> >::const_iterator, std::vector<std::basic_string<char> >::const_iterator, const string&)'
i1 = find(colnames.begin(),colnames.end(),cn);
即使std::find 也无法解决这个问题。
编译器给出了另一个线索:
note: template argument deduction/substitution failed:
note: '__gnu_cxx::__normal_iterator<const std::basic_string<char>*, std::vector<std::basic_string<char> > >' is not derived from 'std::istreambuf_iterator<_CharT>'
i1 = std::find(colnames.begin(),colnames.end(),cn);
有什么线索吗?
【问题讨论】:
-
@ks1322 不,thst 没有解决,用编译器提供的更多线索编辑了我的 Qs
-
您是否包含了查找功能的更正确的头文件?您应该创建一个完整但最小的示例来显示您遇到的错误,以便其他人可以复制/粘贴并自己尝试。
-
@nos,我添加了#include
,现在完美了!非常感谢。这与早期版本的编译器(非 C++11)完美编译,无论如何都很好
标签: c++ string c++11 vector find