10.38
①输入迭代器:用于比较俩个迭代器等或者不等,前置和后置递增(++)操作,
②输出迭代器
③前向迭代器
④双向迭代器
⑤随机访问迭代器
10.39
list的迭代器属于双向迭代器,vector的迭代器属于随机访问迭代器
10.40
copy要求前俩个参数至少是输入迭代器,表示一个输入范围。它读取这个范围里的元素,写入到第三个参数表示的输出序列中,因此第三个参数至少是输出迭代器。
reverse要反向处理序列,因此它要求俩个参数至少是双向迭代器
unique顺序扫描元素,覆盖重复元素,因此要求俩个参数至少是前向迭代器。
“至少”意味着能力更强的迭代器是可接受的
10.41
①把{beg,end)所有old_val替换为new_val
②把{beg,end)所有满足pred的old_val替换为new_val
③
10.42
#include <iostream>
#include <fstream>
#include <list>
#include <string>
#include <algorithm>
using namespace std;
void output_words(const list<string> &words)
{
for(auto iter = words.begin(); iter != words.end(); ++iter)
cout << *iter << " ";
cout <<endl;
}
void elimdups(list<string> &words)
{
output_words(words);
words.sort();
output_words(words);
unique.words(words);
output_words(words);
}
int main(int argc, char *argv[])
{
string word;
list<string> words;
ifstream in(argv[1]);
if (!in)
cerr << "无法打开文件" << endl;
while(in >> word0
words.push_back(wordd);
elimdups(words);
return 0;
}