I want to convert a character to Integer and calculate its frequency but I receive this error! I am using XCODE.
terminating with uncaught exception of type std::invalid_argument: stoi: no conversion .
#include <iostream>
int main(int argc, const char * argv[]) {
std::string s;
std::cin>>s;
int a[27];
for(int i=0;i<s.length();i++)
{
int c;
c=std::stoi(&s[i]);
a[c]++;
}
for(int i=0;i<27;i++)
std::cout<<a[i];
return 0;
}
stoi
- it makes no sense here. What's the expected input? – Igor Tandetnikstoi
? It takes aconst
reference to a string – NathanOliver