• <bdo id='UsOHr'></bdo><ul id='UsOHr'></ul>
      <legend id='UsOHr'><style id='UsOHr'><dir id='UsOHr'><q id='UsOHr'></q></dir></style></legend>
    1. <small id='UsOHr'></small><noframes id='UsOHr'>

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

      直接提升序列化到字符数组

      时间:2023-10-06
        <tbody id='W4GtR'></tbody>

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

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

        • <legend id='W4GtR'><style id='W4GtR'><dir id='W4GtR'><q id='W4GtR'></q></dir></style></legend>

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

                本文介绍了直接提升序列化到字符数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                Boost 序列化文档断言序列化/反序列化项目的方法是使用二进制/文本存档,并在底层结构上使用流.如果我不想将序列化数据用作 std::string,这可以正常工作,但我的目的是将其直接转换为 char* 缓冲区.如何在不创建临时字符串的情况下实现此目的?

                Boost serialization doc's assert that the way to serialize/deserialize items is using a binary/text archive with a stream on the underlying structure. This works fine if I wan't to use the serialized data as an std::string, but my intention is to convert it directly to a char* buffer. How can I achieve this without creating a temporary string?

                解决了!对于那些想要一个例子的人:

                Solved! For the ones that wanted a example:

                char buffer[4096];
                
                boost::iostreams::basic_array_sink<char> sr(buffer, buffer_size);  
                boost::iostreams::stream< boost::iostreams::basic_array_sink<char> > source(sr);
                
                boost::archive::binary_oarchive oa(source);
                
                oa << serializable_object; 
                

                推荐答案

                IIUC,您想写入一个固定大小的预分配数组.

                IIUC, you would like to write to a preallocated array of fixed size.

                您可以使用 boost::iostreams::array_sink(用 stream 给它一个 std::ostream 接口).

                You could use a boost::iostreams::array_sink (wrapped with stream to give it an std::ostream interface) for that.

                这篇关于直接提升序列化到字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何使用自定义库的 boost 库进行性能测试 下一篇:将 C++ 类转换为 JSON

                相关文章

                最新文章

                  <bdo id='8O7VE'></bdo><ul id='8O7VE'></ul>

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