[英]Why is std::string implemented as basic_string of `char` and not `unsigned char`
typedef basic_string<char> string;
All the std::string
facilities in the standard library are using char
. 标准库中的所有
std::string
工具都使用char
。 Why is that? 这是为什么? Although all the characters of the ASCII table (128) fit into the range of a
char
(-128 to 127), many other character encodings are using 8-bits for representation. 尽管ASCII表(128)的所有字符都适合
char
(-128到127)的范围,但是许多其他字符编码使用8位表示。
What is the advantage of having 'negative' values in a string of chars? 在字符串字符中具有“负”值的好处是什么?
字符串文字的类型为const char*
,因此在执行std::string("fooo")
时将需要O(n)转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.