void perm(std::string fixed,std::string perm){
if (perm.length() == 1){
std::cout << fixed + perm << std::endl;
}else{
for (int i=0;i<perm.length();i++){
std::string perm2 = perm;
std::swap(perm2[0],perm2[i]);
perm(fixed + perm[i],perm2.substr(1,perm.length()-1));
}
}
}
This is my first question and I am (very) new to programming. I was working on a mini program which simply prints all the permutations of a string. For example, perm("","123") would be supposed to return the following values
123
132
213
231
312
321
However, on compilation, the g++ compiler returns the following error:
permutations.cpp: In function ‘void perm(std::string, std::string)’:
permutations.cpp:19:29: error: no match for call to ‘(std::string {aka
std::__cxx11::basic_string<char>}) (std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char>)’
19 | perm(fixed + perm[i],perm2.substr(1,perm.length()-1));
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I would like to know the cause of this error and troubleshoot it. Thank you.