Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
error: could not convert ‘(std::string*)(& sol)’ from ‘std::string* {aka std::basic_string*}’ to ‘std::string {aka std::basic_string}’

What I have tried:

C++
#include<limits> 
#include<string>
#include<iostream>
using namespace std;
int returnPermutations(string input, string output[])
{ 
    if(input.length() == 0)
    { 
        output[0] = ""; 
        return 1; 
    } 
    string smallOutput[10000]; 
    int smallSize = returnPermutations(input.substr(1), smallOutput); 
    int k = 0; 
    for(int i = 0; i < smallSize; i++)
    { 
        for(int j = 0; j <=smallOutput[i].length(); j++)
        { 
            output[k++] = smallOutput[i].substr(0,j) + input[0] + smallOutput[i].substr(j); 
        } 
    } 
    return k; 
}
string getStr(string s)
{
    int l;
    l=s.length();
    string r="";
    for(int i=0;i<l;i++)
    {
       if(s[i]!=' ')
         r=r+s[i];        
    }
    return r;
}
int main()
 {
    string sol[10000];
     string s;
     getline(cin,s);
    sol[10000]=getStr(s);
   string output[10000];
   int count = returnPermutations(sol,output);
    for(int i = 0; i < count && i <10000; i++){
        cout << output[i] << endl;
    }
	return 0;
}
Posted
Updated 29-Aug-20 6:35am
v2
Comments
KarstenK 29-Aug-20 12:38pm    
I think that your recursice function call has some flaws. I would use a const int for the 10000 and start to debug it with a 3. ;-)

1 solution

First off, sol[10000] = getStr(s) should crash because the maximum legal index for the sol array is 9999 (its 10000 indices are 0 through 9999).

int count = returnPermutations(sol, output) is invoking the function with sol, which is an array. The way that C++ does this is to pass a pointer to the first element in the array, namely a pointer to the string sol[0]. The function then has to know that it's actually receiving an array argument. But this means that its first argument must be string* input, not string input. This is the cause of the compiler error. But you also invoke returnPermutations with input.substr(1), which is an actual string, so you'll have to decide how to align both usages.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900