#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <iostream>
// g++ 4.9.2 -std=c++11
// function that take a string and return true
// indicating the string has five characters
// or more
bool pred(const std::string &s)
{
return !(s.size() < 5);
}
int main()
{
std::vector<std::string> words;
std::string str;
while (std::cin >> str) {
words.push_back(str);
}
std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(std::cout, " "));
std::cout << "\n";
auto it = std::partition(words.begin(), words.end(), pred);
std::copy(words.begin(), it, std::ostream_iterator<std::string>(std::cout, " "));
std::cout << "\n";
return 0;
}
from C++ primer 5th Exercise 10.13(P.387)