string str = "4fd8bfb78d5291eb809d0beab33acf4ae505e1df"; const char * cstr = str.c_str(); stringstream std; int summ = 0; for(unsigned int i=0; strlen(cstr) > i; i++) { std << cstr[i]; summ += atoi(std.str().c_str()); std.str(""); }
The meaning of the code I think is clear, wondering how you can implement more adequately ...
std::accumulate( str.c_str(), str.c_str() + str.size(), 0, [](size_t sz, char c){ return sz + (c - '0'); } );
function, of course, you need to file so that the letters are correctly processed - fogbit