I am trying to add all the digits of a string in c++, but it cannot passes all test cases. My code is given below.
#include <iostream>
using namespace std;
int main()
{
string str;
long long int count=0;
cin>>str;
for(int i=0;i<str.length();i++)
{
count+=(str[i]-'0');
}
cout<<count<<endl;
return 0;
}
Don't know how to resolve this problem can anyone help me out???