代码从C++引擎(3第三个)。 错误是:在Ubuntu Linux上使用g ++编译引擎示例代码时出错
* filterString.cpp:在函数 '诠释主()': filterString.cpp:32:68:错误:不能转换 '__gnu_cxx :: __ normal_iterator *,性病::矢量>>'到'std :: string * {aka std :: basic_string }'在初始化中
请帮我分析一下错误, 谢谢。
代码:
#include <string>
#include <algorithm>
#include <iterator>
#include <vector>
#include <iostream>
using namespace std;
template <class InputIterator>
void filter_string(InputIterator first, InputIterator last, string filt_elems = string("\",?.")) {
for (; first != last; first++){
string:: size_type pos = 0;
while ((pos = (*first).find_first_of(filt_elems, pos)) != string::npos)
(*first).erase(pos, 1);
}
}
bool length_less (string s1, string s2) {
return s1.size() < s2.size();
}
int main() {
istream_iterator<string> input(cin), eos;
vector<string> text;
copy(input, eos, back_inserter(text));
string filt_elems("\",.?;:");
filter_string(text.begin(), text.end(), filt_elems);
int cnt = text.size();
string *max = max_element(text.begin(), text.end(), length_less);
int len = max->size();
cout << "The number of words read is " << cnt << endl;
cout << "The longest word has a length of " << len << endl;
cout << "The longest word is " << *max << endl;
return 0;
}
如果您正在从一本书或其他旧的(互联网时间)来源开始工作,您可能正在处理对事物如何运作的理解的变化,因为语言已经得到了更好的指定。设置一个'-std ='可以让你在编译器中使用一个更早的理解。 – dmckee
对不起,我完全无法理解。尤其是这样的话:“设置-std =可能让你在编译器中使用更早的理解”。你能否从一点到另一点解释它!非常感谢! –
G ++采用'std = C++ 98'或'std = C++ = 0x'形式的参数。选择正确的*可能会得到g ++来处理代码。 – dmckee