<legend id='mMIyT'><style id='mMIyT'><dir id='mMIyT'><q id='mMIyT'></q></dir></style></legend>
<i id='mMIyT'><tr id='mMIyT'><dt id='mMIyT'><q id='mMIyT'><span id='mMIyT'><b id='mMIyT'><form id='mMIyT'><ins id='mMIyT'></ins><ul id='mMIyT'></ul><sub id='mMIyT'></sub></form><legend id='mMIyT'></legend><bdo id='mMIyT'><pre id='mMIyT'><center id='mMIyT'></center></pre></bdo></b><th id='mMIyT'></th></span></q></dt></tr></i><div id='mMIyT'><tfoot id='mMIyT'></tfoot><dl id='mMIyT'><fieldset id='mMIyT'></fieldset></dl></div>
  • <small id='mMIyT'></small><noframes id='mMIyT'>

      <bdo id='mMIyT'></bdo><ul id='mMIyT'></ul>

      <tfoot id='mMIyT'></tfoot>

      1. 为什么 C++ 流使用 char 而不是 unsigned char?

        Why do C++ streams use char instead of unsigned char?(为什么 C++ 流使用 char 而不是 unsigned char?)
        <legend id='hBW2Y'><style id='hBW2Y'><dir id='hBW2Y'><q id='hBW2Y'></q></dir></style></legend>
          <tfoot id='hBW2Y'></tfoot>

          <small id='hBW2Y'></small><noframes id='hBW2Y'>

          <i id='hBW2Y'><tr id='hBW2Y'><dt id='hBW2Y'><q id='hBW2Y'><span id='hBW2Y'><b id='hBW2Y'><form id='hBW2Y'><ins id='hBW2Y'></ins><ul id='hBW2Y'></ul><sub id='hBW2Y'></sub></form><legend id='hBW2Y'></legend><bdo id='hBW2Y'><pre id='hBW2Y'><center id='hBW2Y'></center></pre></bdo></b><th id='hBW2Y'></th></span></q></dt></tr></i><div id='hBW2Y'><tfoot id='hBW2Y'></tfoot><dl id='hBW2Y'><fieldset id='hBW2Y'></fieldset></dl></div>
                <bdo id='hBW2Y'></bdo><ul id='hBW2Y'></ul>
                    <tbody id='hBW2Y'></tbody>

                  本文介绍了为什么 C++ 流使用 char 而不是 unsigned char?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直想知道为什么 C++ 标准库使用 char 类型而不是 unsigned char 类型来实例化 basic_[io]stream 及其所有变体.char 意味着(取决于它是否有符号)你可以有像 get() 这样的操作的上溢和下溢,这将导致所涉及的变量的实现定义的值.另一个例子是当你想使用 put 函数将一个未格式化的字节输出到 ostream 时.

                  I've always wondered why the C++ Standard library has instantiated basic_[io]stream and all its variants using the char type instead of the unsigned char type. char means (depending on whether it is signed or not) you can have overflow and underflow for operations like get(), which will lead to implementation-defined value of the variables involved. Another example is when you want to output a byte, unformatted, to an ostream using its put function.

                  有什么想法吗?

                  注意:我还是不太相信.所以如果你知道最终答案,你仍然可以发布它.

                  Note: I'm still not really convinced. So if you know the definitive answer, you can still post it indeed.

                  推荐答案

                  可能我误解了这个问题,但是从 unsigned char 到 char 的转换不是未指定的,它依赖于实现(C++ 标准中的 4.7-3).

                  Possibly I've misunderstood the question, but conversion from unsigned char to char isn't unspecified, it's implementation-dependent (4.7-3 in the C++ standard).

                  C++ 中 1 字节字符的类型是char",而不是unsigned char".这为实现在平台上做最好的事情提供了更多的自由(例如,标准机构可能认为存在有符号字节算术比无符号字节算术更快的 CPU,尽管这是我的推测).也是为了与 C 兼容.从 C++ 中消除这种存在不确定性的结果是 C# ;-)

                  The type of a 1-byte character in C++ is "char", not "unsigned char". This gives implementations a bit more freedom to do the best thing on the platform (for example, the standards body may have believed that there exist CPUs where signed byte arithmetic is faster than unsigned byte arithmetic, although that's speculation on my part). Also for compatibility with C. The result of removing this kind of existential uncertainty from C++ is C# ;-)

                  鉴于存在char"类型,我认为即使未定义其符号性,通常的流也可以使用它.因此,也许您的问题可以通过为什么 C++ 不将 char 定义为无符号?"的答案来回答?

                  Given that the "char" type exists, I think it makes sense for the usual streams to use it even though its signedness isn't defined. So maybe your question is answered by the answer to, "why didn't C++ just define char to be unsigned?"

                  这篇关于为什么 C++ 流使用 char 而不是 unsigned char?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                  <small id='Vt345'></small><noframes id='Vt345'>

                      <i id='Vt345'><tr id='Vt345'><dt id='Vt345'><q id='Vt345'><span id='Vt345'><b id='Vt345'><form id='Vt345'><ins id='Vt345'></ins><ul id='Vt345'></ul><sub id='Vt345'></sub></form><legend id='Vt345'></legend><bdo id='Vt345'><pre id='Vt345'><center id='Vt345'></center></pre></bdo></b><th id='Vt345'></th></span></q></dt></tr></i><div id='Vt345'><tfoot id='Vt345'></tfoot><dl id='Vt345'><fieldset id='Vt345'></fieldset></dl></div>
                      • <legend id='Vt345'><style id='Vt345'><dir id='Vt345'><q id='Vt345'></q></dir></style></legend>

                        • <bdo id='Vt345'></bdo><ul id='Vt345'></ul>

                            <tfoot id='Vt345'></tfoot>
                              <tbody id='Vt345'></tbody>