• <tfoot id='gU0gX'></tfoot>
      • <bdo id='gU0gX'></bdo><ul id='gU0gX'></ul>

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

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

        <legend id='gU0gX'><style id='gU0gX'><dir id='gU0gX'><q id='gU0gX'></q></dir></style></legend>

        如何使用类似`std::basic_istream&lt;std::byte&gt;`

        时间:2023-10-18

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

              <tbody id='zLbIL'></tbody>

              • <small id='zLbIL'></small><noframes id='zLbIL'>

                <legend id='zLbIL'><style id='zLbIL'><dir id='zLbIL'><q id='zLbIL'></q></dir></style></legend>
                  <bdo id='zLbIL'></bdo><ul id='zLbIL'></ul>
                  本文介绍了如何使用类似`std::basic_istream&lt;std::byte&gt;`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这个问题旨在将 std::byte 与标准输入输出一起使用.

                  是否有计划将read(_bytes)write(_bytes) 的适当函数重载添加到basic_istream 的接口中> 和 basic_ostream 在未来的标准中?什么理由反对它?我知道应该保留 CharT* 重载.如何使用 std::byte?我目前在我的项目功能中定义

                  std::istream&读取(std::istream&,std::byte*,std::streamsize)std::ostream&写(std::ostream&,const std::byte*,std::streamsize)

                  这些使用 reinterpret_cast<>char* resp.const char* 但我相信这取决于 char 的大小.我错了吗?char 总是 1 字节 吗?

                  我试图制作 std::basic_istream 但它缺少 std::char_traits 等等.有没有人已经做过这种事情?

                  解决方案

                  不要.

                  无论您是在文本模式"还是二进制模式"下操作,您所做的基本上都是对字符进行操作.

                  std::byte 不是为了这个目的,这就是它没有这些功能的原因.确实,它是故意引入而不是来拥有它们的!

                  <块引用>

                  enum class byte : unsigned char {} ; (C++17 起)

                  std::byte 是一种独特的类型,它实现了 C++ 语言定义中指定的字节概念.

                  charunsigned char 一样,它可以用来访问被其他对象占用的原始内存(对象表示),但与那些类型不同的是,它不是字符类型,也不是算术类型.一个字节只是位的集合,只为它定义了按位逻辑运算符.

                  http://en.cppreference.com/w/cpp/types/byte

                  <小时><块引用>

                  有人已经让这种事情奏效了吗?

                  不,正如上文所述,每个人都故意不这样做.

                  使用 charunsigned char,就像我们几十年来所做的那样!

                  This question aims for using std::byte with standard input-output.

                  Are there any plans to add proper function overloads for read(_bytes) and write(_bytes) to the interfaces of basic_istream<CharT> and basic_ostream<CharT> in a future standard? What reasons speak against it? I understand that the CharT*-overloads should be kept. What can I do to use std::byte? I currently define in my project functions

                  std::istream& read(std::istream&, std::byte*, std::streamsize)
                  std::ostream& write(std::ostream&, const std::byte*, std::streamsize)
                  

                  These use reinterpret_cast<> to char* resp. const char* but I believe this depends on the size of char. Am I wrong? Is char always 1 byte?

                  I tried to make std::basic_istream<std::byte> but it is missing std::char_traits<std::byte> and so on. Did anyone make this kind of thing work already?

                  解决方案

                  Don't.

                  Whether you're operating in "text mode" or "binary mode", what you are still doing fundamentally is acting on characters.

                  std::byte is not for this purpose, and that's why it does not have these features. Indeed, it was deliberately introduced not to have them!

                  enum class byte : unsigned char {} ; (since C++17)

                  std::byte is a distinct type that implements the concept of byte as specified in the C++ language definition.

                  Like char and unsigned char, it can be used to access raw memory occupied by other objects (object representation), but unlike those types, it is not a character type and is not an arithmetic type. A byte is only a collection of bits, and only bitwise logic operators are defined for it.

                  http://en.cppreference.com/w/cpp/types/byte


                  Did anyone make this kind of thing work already?

                  No, everyone deliberately didn't, as explored above.

                  Use char or unsigned char, as we have done for decades!

                  这篇关于如何使用类似`std::basic_istream&lt;std::byte&gt;`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C++ 和 C 文件 I/O 下一篇:使用/不使用 ios::binary 模式打开流时使用读/写的区别

                  相关文章

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

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

                      <legend id='wLMWR'><style id='wLMWR'><dir id='wLMWR'><q id='wLMWR'></q></dir></style></legend>
                        <bdo id='wLMWR'></bdo><ul id='wLMWR'></ul>