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?
CodePudding user response:
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);
CodePudding user response:
use std:: before stoi (std::stoi)
std::stoi arguments are not true, so you are not using correct syntax, try to fix it as follows:
int stoi( const std::string& str, std::size_t* pos = nullptr, int base = 10 );
int stoi( const std::wstring& str, std::size_t* pos = nullptr, int base = 10 );
and at least use c 11
