I use code:

for(int i = 1; i < n; i++){ cout<<stoi(s1[i]) + stoi(s1[i-1]); //ошибка error: no matching function for call to 'stoi(__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type&)'| } 

What is the problem and how to fix it? a string of numbers only.

  • one
    What type of array is s1 ? - ߊߚߤߘ
  • atoi function is to translate - joystick
  • @joystick: The atoi function for twenty years now is not intended for practical use either in C or C ++, It exists only for backward compatibility. Forget about atoi . - AnT
  • @AnT well, what then can be used instead of atoi? - shumik_UA

2 answers 2

You seem to have a string. The string does not consist of "numbers", but of numbers . The numbers are translated into the corresponding numerical values ​​using the expression s[i] - '0' .

If this is not what you need, then take care of a more or less understandable description of the problem. A meaningless "string of numbers only" is not enough.

    The fact is that I tried to convert a character (digit) by a function from a string to an int in turn, BUT one character is not a string but a char. Problem solved