10.6
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> ivec = {1, 2, 3, 4, 5};
fill_n(ivec.begin(), ivec.size(), 0);
for (auto i : ivec)
cout << i << endl;
return 0;
}
10.7 (a) vec为空,应改为copy(lst.cbegin(), lst.cend, back_inserter(vec)); (b) 尽管用reserve为vec分配了空间,但vec中没有元素,仍然是空的,应改为:fill_n(back_inserter(vec), 10, 0);
10,8 标准库算法不直接操作容器,只操作迭代器;当传递给算法普通迭代器,无法增删元素;当传递给算法插入器,这种迭代器能够向容器添加元素。算法不会改变容器大小,迭代器可能改变容器大小。
10.9
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void elimDups(vector<string> &words)
{
for (auto w