How do I convert string to ASCII?

If the string was cab
How would I convert to an ascii value so it would be 294?
thanks.

Sum the values of the characters:

string[0] + string[1] + ... + string[length-1]

and cast the result to an integer
Last edited on
how would you do that?
Im sort of new to c++
I'd suggest you a for loop, from 0 to the string length-1 and use subscripting to add to the sum:
sum += yourstring[i];
Last edited on
oooo thanks so much!!
1
2
#include <numeric>
std::accumulate(string.begin(), string.end(), 0);
subscripting?
subscripting is the [ ] operator
Topic archived. No new replies allowed.