So I have this function in C++11:
bool ccc(const string cc) {
vector<string> digits;
int aux;
for(int n = 0; n < cc.length(); ++n) {
digits.push_back(to_string(cc[n])); }
for(int s = 1; s < digits.size(); s += 2) {
aux = stoi(digits[s]);
aux *= 2;
digits[s] = to_string(aux);
aux = 0;
for(int f = 0; f < digits[s].length(); ++f) {
aux += stoi(digits[s][f]); }
digits[s] = to_string(aux);
aux = 0; }
for(int b = 0; b < digits.size(); ++b) {
aux += stoi(digits[b]); }
aux *= 9;
aux %= 10;
return (aux == 0); }
And I get this error when compiling with G++ WITH THE -std=c++11 flag:
crecarche.cpp: In function ‘bool ccc(std::string)’:
crecarche.cpp:18:12: error: no matching function for call to ‘stoi(__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type&)’
18 | aux += stoi(digits[s][f]); }
| ~~~~^~~~~~~~~~~~~~
But I used the stoi function after and I did not get any error with that line.
Why is the compiler throwing me this error and how can I fix it?
Thanks in advanced.
Aucun commentaire:
Enregistrer un commentaire