I think the best solution is typeing new code in with you use backtrack for permutations. I typed something like that you should provide vector V with chars you want for combinations and call the function bactrack like bactrack(0,length_of_expected_string). You will got permutations in set S in alphaetical order. You can uncommet code for typenig combinations on a screen.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<list>
#include<vector>
#include<math.h>
#include<iomanip>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<map>
#include<set>
using namespace std;
vector<char> V;
vector<char> combination;
set<vector<char> > S;
void backtrack(int depth,int expected_length)
{
if(depth<expected_length)
{
for(int i=0;i<V.size();i++)
{
combination.push_back(V[i]);
backtrack(depth+1,expected_length);
combination.pop_back();
}
}
else
{
/*for(int i=0;i<combination.size();i++)
{
cout<<combination[i];
}
cout<<endl;*/
S.insert(combination);
}
}
int main()
{
backtrack(0,3);
for(auto it=S.begin();it!=S.end();it++)
{
/*
for(int i=0;i<(*it).size();i++)
{
cout<<(*it)[i];
}
cout<<endl;*/
}
}