Sum of Digits in a String (using string objects) C++
Should be
for (int i = 0; i < digits.length(); i++)
{
cout << digits.at(i) << endl;
num = digits.at(i) - '0';
assert(0 <= num && num <= 9);
cout << num << endl; // Displays what came out of function
total += num;
}
To convert a single number you don't need complex things like stringstream.
You can also use (not recommended) istringstream(digits.substr(i, 1))