C++ code that generates all possible permutations of the given string and substrings within.