The obvious way to solve this is to repeatedly call next_permutation() from the standard library. Another way to solve it is to implement what next_permutation() does and I have done that in a previous solution:
I thought I would have a go at solving this by using the nature of recursive calls to go through combinations. The following is a logically simple but not very efficient way of doing it:
And here is the source code:
A more efficient solution is https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/ although this does not generate outputs in lexicographical order.