• <bdo id='uo5uy'></bdo><ul id='uo5uy'></ul>
  1. <legend id='uo5uy'><style id='uo5uy'><dir id='uo5uy'><q id='uo5uy'></q></dir></style></legend>

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

      如何仅使用 boost 将字符串编码为 base64?

      时间:2023-07-20

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

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

              • <bdo id='YlzsG'></bdo><ul id='YlzsG'></ul>
                  <tbody id='YlzsG'></tbody>

                本文介绍了如何仅使用 boost 将字符串编码为 base64?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试将一个简单的 ASCII 字符串快速编码为 base64(使用 boost::asio 的基本 HTTP 身份验证),而不是粘贴任何新的代码代码或使用任何超出 boost 的库.

                I'm trying to quickly encode a simple ASCII string to base64 (Basic HTTP Authentication using boost::asio) and not paste in any new code code or use any libraries beyond boost.

                简单的签名如下:string Base64Encode(const string& text);

                我再次意识到该算法很简单,并且有很多库/示例可以这样做,但我正在寻找一个干净的提升示例.我找到了 boost 序列化,但没有明确的例子,也没有来自谷歌的例子.http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/dataflow.html

                Again I realize the algorithm is easy and there are many libraries/examples doing this but I'm looking for a clean boost example. I found boost serialization but no clear examples there or from Google. http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/dataflow.html

                如果不将实际的 base64 算法显式添加到我的代码中,这是否可行?

                Is this possible without adding the actual base64 algorithm explicitly to my code?

                推荐答案

                我改进了您提供的链接中的示例:

                I improved the example in the link you provided a little:

                #include <boost/archive/iterators/base64_from_binary.hpp>
                #include <boost/archive/iterators/insert_linebreaks.hpp>
                #include <boost/archive/iterators/transform_width.hpp>
                #include <boost/archive/iterators/ostream_iterator.hpp>
                #include <sstream>
                #include <string>
                #include <iostream>
                
                
                int main()
                {
                    using namespace boost::archive::iterators;
                
                    std::string test = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ornare ullamcorper ipsum ac gravida.";
                
                    std::stringstream os;
                    typedef 
                        insert_linebreaks<         // insert line breaks every 72 characters
                            base64_from_binary<    // convert binary values to base64 characters
                                transform_width<   // retrieve 6 bit integers from a sequence of 8 bit bytes
                                    const char *,
                                    6,
                                    8
                                >
                            > 
                            ,72
                        > 
                        base64_text; // compose all the above operations in to a new iterator
                
                    std::copy(
                        base64_text(test.c_str()),
                        base64_text(test.c_str() + test.size()),
                        ostream_iterator<char>(os)
                    );
                
                    std::cout << os.str();
                }
                

                这会在控制台上打印出经过良好格式化的 base64 编码字符串,每 72 个字符有一个换行符,准备好放入电子邮件中.如果您不喜欢换行符,请继续使用:

                This prints the string encoded base64 nicely formated with a line break every 72 characters onto the console, ready to be put into an email. If you don't like the linebreaks, just stay with this:

                    typedef 
                        base64_from_binary<
                           transform_width<
                                const char *,
                                6,
                                8
                            >
                        > 
                        base64_text;
                

                这篇关于如何仅使用 boost 将字符串编码为 base64?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:是否可以使用 CMake 构建 Boost? 下一篇:Boost::multi_array 性能问题

                相关文章

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

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