How do I convert string to ASCII?

Apr 19, 2009 at 12:51pm
If the string was cab
How would I convert to an ascii value so it would be 294?
thanks.

Apr 19, 2009 at 12:55pm
Sum the values of the characters:

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

and cast the result to an integer
Last edited on Apr 19, 2009 at 12:55pm
Apr 19, 2009 at 12:56pm
how would you do that?
Im sort of new to c++
Apr 19, 2009 at 1:12pm
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 Apr 19, 2009 at 1:12pm
Apr 19, 2009 at 1:31pm
oooo thanks so much!!
Apr 19, 2009 at 2:48pm
1
2
#include <numeric>
std::accumulate(string.begin(), string.end(), 0);
Apr 20, 2009 at 8:54am
subscripting?
Apr 20, 2009 at 11:34am
subscripting is the [ ] operator
Topic archived. No new replies allowed.