How do I convert a c++ string into a unsigned char?
Thanks
How do I convert a c++ string into a unsigned char?
Thanks
Last edited by erik_markman; 10-02-2003 at 10:39 AM.
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();
The information given in this message is known to work on FreeBSD 4.8 STABLE.
*The above statement is false if I was too lazy to test it.*
Please take note that I am not a technical writer, nor do I care to become one.
If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
Don't assume that I'm ever entirely serious or entirely joking.