I'm using vc++ 2003, and on my compiler, if a character in a string sequence is larger than 0x80, it shows some pretty weird behavior when used with cout.
For example
This will print outCode:char ct[] = {0xa1, 0xc1, 0xbf, 0xff, 0x00}; string s(ct); string::iterator its; cout.setf(ios_base::hex, ios_base::basefield); cout.setf(ios_base::uppercase); for(its = s.begin(); its != s.end(); its++) cout << setw(3) << (int) *its;
However, if I define the string instead as basic_string<unsigned char>:Code:FFFFFFA1FFFFFFC1FFFFFFBFFFFFFFFF
This prints out:Code:unsigned char ct[] = {0xa1, 0xc1, 0xbf, 0xff, 0x00}; basic_string<unsigned char> s(ct); basic_string<unsigned char>::iterator its; cout.setf(ios_base::hex, ios_base::basefield); cout.setf(ios_base::uppercase); for(its = s.begin(); its != s.end(); its++) cout << setw(3) << (int) *its;
Why is cout giving me that extra garbage in the upper bits (i.e. +8) if I designate it a basic_string as a plain char sequence? If you expand signed characters, do they become signed integers?Code:A1 C1 BF FF



LinkBack URL
About LinkBacks


