void justPrintSubsequnce(string input, string output){
if(input.length() == 0){
cout<<output<<" ";
return;
}
justPrintSubsequnce(input.substr(1),output);
justPrintSubsequnce(input.substr(1),output[0]+input[0]);
}
I tried to write a function to print out the subsequences of a string (input) using recursion and got this error for output[0] + input[0]:
no suitable constructor exists to convert from "int" to "std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator>"
output[0]+input[0]is attempting to add twochar's together and forms an integer expression.Instead of this:
This:
You can inline the expression for "s" into the function call directly.
While we're here, if you declare your function like this:
You'll avoid redundant copies of strings (hence, less memory) and enable the compiler to do more optimizations.