#include #include #include #include template void print(const std::vector &vec) { for (typename std::vector::const_iterator i = vec.begin(); i != vec.end(); ++i) { std::cout << *i; if ((i + 1) != vec.end()) std::cout << ","; } std::cout << std::endl; } int main() { //Permutations for strings std::string example("Hello"); std::sort(example.begin(), example.end()); do { std::cout << example << '\n'; } while (std::next_permutation(example.begin(), example.end())); // And for vectors std::vector another; another.push_back(1234); another.push_back(4321); another.push_back(1234); another.push_back(9999); std::sort(another.begin(), another.end()); do { print(another); } while (std::next_permutation(another.begin(), another.end())); return 0; }