if s is of type string in C++, s[n] will return a char, not unsigned char. This creates lots of problem for me since I have to do type conversion everywhere.
The following code will not print "yes".
#include <string>
#include <iostream>
using namespace std;
typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned short uint16;
typedef unsigned char uchar;
int main(int argc, char *argv[]) {
string s = "h\x8fllo world";
printf("%d\n", s[1]);
if (s[1] == 0x8f) {
printf("yes\n");
}
return 0;
}
I can make it work by changing the above to be if ((uchar*)(s[1] == 0x8f) {, but there are too many occurrences. I really hoped that the [] operator on string class could return a unsigned char!! Is there a way to do this?