NoSpam@NoPain.com says...
[ ... ]
* Write a program to count word size of greater than or equal to 4
including printing the list of unique words in the input. Test your
program by running it on program's source file.
People have already talked quite a bit about the part you really asked
about, but I thought I'd add a slightly different approach to the task
itself:
#include <iostream>
#include <set>
#include <algorithm>
#include <string>
class shorter_than {
size_t x;
public:
shorter_than(size_t c) : x(c) {}
bool operator()(std::string const &s) {
return s.length() < x;
}
};
int main() {
std::set<std::string> words;
std::remove_copy_if(
std::istream_iterator<std::string>(std::cin),
std::istream_iterator<std::string>(),
std::inserter(words, words.begin()),
shorter_than(4));
std::cout << words.size() << " unique words:\n";
std::copy(words.begin(), words.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
return 0;
}
std::remove_copy_if copies one container to another, leaving out any
that meet the specified criteria. std::set only allows one copy of a
specific item to be inserted, so each one is automatically unique,
without explicitly removing duplicates.