I have fixed it another way but I still want to know why stoi is not working here. This is the code:
#include <string>
#include<iostream>
std::string fakeBin(std::string str){
for(int i=0;i<str.size();i++){
int number=stoi(str[i]);
std::cout<<number<<std::endl;
}
return "a";
}
int main()
{
fakeBin("12354234");
return 0;
}
while compiling
int number=stoi(str[I]);
I get this error:
'stoi' was not declared in this scope
Can you explain me why I am getting this error?
You should write std:: stoi or you can add a line " using namespace std; " just after the headerfile.
There are another mistake : stoi work only strings .here str[i] is a character . so you have to create a empty string variable string s=""; and then s= s+ str[i] ; after this you can do std:: stoi(s);