int main()
{
vector<string> words = {
"the", "quick", "red", "fox", "jumps", "over", "the", "slow", "the", "turtle", "the"
};
sort(words.begin(), words.end()); // 排序
cout << words.size() << endl;
for (auto &i : words)
cout << i << " ";
cout << endl;
auto end_unique = unique(words.begin(), words.end()); // 重复元素放在后面
cout << words.size() << endl;
for (auto &i : words)
cout << i << " ";
cout << endl;
return 0;
}
运行结果:
11
fox jumps over quick red slow the the the the turtle
11
fox jumps over quick red slow the turtle the the
size 出来的大小都是正常的,但遍历打印就是少一个。
编译器:g++ 9.4.0
运行环境:Ubuntu 20.04