代码来自C++ Primer(3 third)。错误是:
*filterString.cpp:在函数 'int main()' 中:filterString.cpp:32:68:错误:无法将 '__gnu_cxx::__normal_iterator*, std::vector > >' 转换为 '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;
}