How to print all the possible combination of a string in C++

One of my friend asked a question in my previous post. His question was "If you have to enter a string How can we print all the possible combination of that.

One of my friend asked a question in my previous post. His question was "If you have to enter a string How can we print all the possible combination of that.
Like if you enter "abc"
then result is : abc, acb, bca, bac, cab, cba"

So here is how to get the the total possible combination of the entered character or word. This is only for three character word you can increase it if you want. The logic is explained below.
 C++ code to find all combination of a word

## Logic behind printing all the possible combination of a string

The logic behind the code is very simple. See firstly I used a Factorial function to find the total no. of possible combination if you type a word bigger than 3 it will show you the possible combination but the possible combination list will not be shown correctly as this code has been designed to show only the combinations of only 3 letter words. Here is the code.
```#include<iostream>
#include <cstring>
using namespace std;

int factorial(int n){
int accum = 1;
while(n > 0){
accum *= n;n--;
}
return accum;
}

int main(){
char word[4];
cout<<"Enter the word without space: ";
cin>>word;
int len=strlen(word);
cout<<endl<<factorial(len)<<" possible combinations. They are : n";
for(int first = 0; first< len; first++) {
for (int second = 0; second < len; second++) {
if (second==first)
continue;
for (int third = 0; third < len; third++) {
if (third==first)
continue;
if (third==second)
continue;
cout<< word[first]<< word[second]<< word[third]<<endl;
}
}}
return 0;
}```
In the main() I wrote three "for()" loops which is for first, second & third letters respectively.  The rest of the code is self understood. If you have any problems regarding the code, Please enter it in comment section.

Name

ltr
item
MindxMaster: How to print all the possible combination of a string in C++
How to print all the possible combination of a string in C++
One of my friend asked a question in my previous post. His question was "If you have to enter a string How can we print all the possible combination of that.