简体   繁体   English

为什么std :: string实现为char的basic_string而不是unsigned char的

[英]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.

相关问题 字符串文字转换为basic_string <unsigned char> - String literal to basic_string<unsigned char> 将cout与basic_string <unsigned char>一起使用 - Using cout with basic_string<unsigned char> 无符号字符的basic_string值类型 - basic_string of unsigned char Value Type 转换 std::basic_string<Char> 串起来 - Convert std::basic_string<Char> to string std :: string {aka std :: basic_string <char> 分配给&#39;&#39;&#39;char *&#39; - std::string {aka std::basic_string<char>}' to 'char*' in assignment| 将basic_string <unsigned char>转换为basic_string <char>,反之亦然 - Convert basic_string<unsigned char> to basic_string<char> and vice versa 无法从&#39;const std :: __ 1 :: basic_string转换 <char> 到&#39;std :: __ 1 :: basic_string <char> *” - No viable conversion from 'const std::__1::basic_string<char> to 'std::__1::basic_string<char> *' 错误:无法转换 &#39;std::basic_string<char> &#39; 到 &#39;char&#39; 赋值 - error: cannot convert 'std::basic_string<char>' to 'char' in assignment ostream和运算符std :: basic_string <char, std::char_traits<char> ,std :: allocator <char> &gt;? - ostream and operator std::basic_string<char, std::char_traits<char>, std::allocator<char>>? 错误:无法从&#39;std :: string * {aka std :: basic_string转换 <char> *}&#39;为&#39;std :: string {aka std :: basic_string <char> }&#39;| - error: could not convert from 'std::string* {aka std::basic_string<char>*}' to 'std::string {aka std::basic_string<char>}'|
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM