How do I convert a c++ string into a unsigned char?
Thanks
Printable View
How do I convert a c++ string into a unsigned char?
Thanks
edit:
It is probably not the best method, but if you are pretty sure that you're string contains a correct char, you can do the following:
1. Get the c_str.
2. Use atoi().
3. Make a cast.
You can't generally convert a string to a char... A typical string is a string-of-characters, and won't fit into one type-char variable.
If your string is only one character long, you can "extract" that character.
Or, you can make a char equal to any one of the characters in a string.
Or, you can make a character string (AKA C-style string, or array of characters) that is equal to your C++ string.
Sorry I don't have any examples for you... No books or compiler with me... I might screw it up. :(
>How do I convert a c++ string into a unsigned char?
I'll leave it up to you to figure out if this particular solution is useful or not. :)Code:unsigned char ch = accumulate(s.begin(), s.end(), 0) % numeric_limits<unsigned char>::max();