- C++17 STL Cookbook
- Jacek Galowicz
- 109字
- 2025-04-04 19:00:07
Putting it together
In the end, all the action happens during the std::copy call:
copy(input_iterator_begin, input_iterator_end, insert_iterator);
This call pulls the next word token out of std::cin via the input iterator and pushes it into our std::set. Afterward, it increments both iterators, and checks whether the input iterator is equal to the input end iterator counterpart. If it is not, then there are still words left in the standard input, so it will repeat.
Duplicate words are automatically dropped. If the set already contains a specific word, adding it again has no effect. This would be different in an std::multiset as, in contrast, it would accept duplicates.