cout works with string (a.k.a. basic_string<char>
) and all number types (int
, char
, unsigned char
, double
, etc.). However it cannot handle basic_string<unsigned char>
.
#include <iostream>
#include <string>
int main()
{
std::basic_string<unsigned char> zzz(3, 'z');
std::cout << zzz << std::endl;
return 0;
}
This doesn't compile with
error: invalid operands to binary expression ('ostream' (aka 'basic_ostream<char>') and 'std::basic_string<unsigned char>')
I would expect this to behave the same way as string. Is there a reason why ostream doesn't handle std::basic_string<unsigned char>
?