How would I convert a string to an integer? I found a method online, but I don't really know how it works. The method is subtracting the character '0' from the character. Supposedly, this makes it an array, but I do not know why. Can anyone explain why? And are there any other methods of approaching this?
A short program using the method I found online:
#include <iostream>
using namespace std;
int main()
{
string st = "12345";
int sum = 0;
for(int i = 0; i < st.size(); i++)
sum += (st[i] - '0');
cout << sum;
}