Not able to debug what's the error in my code need to convert string to integer

#include
#include
#include

using namespace std;
map<char,int> m;

int string_to_int(string str,map<char,int>& m){
int len = str.length();
if(len == 0)
return 0;
else if(len == 1){
return m[str[0]];
}

char k = str[0];

return m[k] * (10 * (len-1)) + string_to_int(str.substr(1,(len-1)),m);

}

int main(){

m['0'] = 0;
m['1'] = 1;
m['2'] = 2;
m['3'] = 3;
m['4'] = 4;
m['5'] = 5;
m['6'] = 6;
m['7'] = 7;
m['8'] = 8;
m['9'] = 9;

string str;

cin>>str;

cout<<string_to_int(str,m);
cout<<endl;
return 0;

}

hi… pls save ur code on ide and send link…

ok… so u just have to use power function
image
I have corrected ur code… its working fine now https://ide.codingblocks.com/s/603772

i hope it clears all ur doubts??

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.