Giving out of range and runtime error because of stoi......Please ignore...have solved it


#1
terminate called after throwing an instance of 'std::out_of_range'

what(): stoi
Getting runtime error why ?
int bintodec(int bin_num){
int dec = 0;
int remainderr=0, raisepowertwo=0;
while(bin_num!=0){
remainderr = bin_num%10;
bin_num /= 10;
if(remainderr)
dec += 1*pow(2, raisepowertwo);
raisepowertwo++;
}
return dec;
}
void backtracking(string temp, vector &ans, int index, int n){
if(index > n){
ans.push_back(stoi(temp));
}
for(int i=0; i<2; i++){
if(i==0)
temp += ‘0’;
else
temp += ‘1’;
}
backtracking(temp, ans, index+1, n);
}
vector Solution::grayCode(int A) {
vector ans;
string store_sequence = “”;
backtracking(store_sequence, ans, 0, A);
return ans;
}