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

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

      如何将 std::string 复制到 std::vector<char> 中?

      时间:2023-09-15
      <tfoot id='9yZEx'></tfoot>
        <bdo id='9yZEx'></bdo><ul id='9yZEx'></ul>

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

            • <small id='9yZEx'></small><noframes id='9yZEx'>

                <tbody id='9yZEx'></tbody>

              • <legend id='9yZEx'><style id='9yZEx'><dir id='9yZEx'><q id='9yZEx'></q></dir></style></legend>
              • 本文介绍了如何将 std::string 复制到 std::vector<char> 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                可能的重复:
                将 std::string 转换为 std::vector

                我试过了:

                std::string str = "hello";
                std::vector<char> data;
                std::copy(str.c_str(), str.c_str()+str.length(), data);
                

                但它不起作用=(所以我想知道如何将 std::string 复制到 std::vector<char>std::vector<uchar> ?

                but it does not work=( So I wonder How to copy std::string into std::vector<char> or std::vector<uchar> ?

                推荐答案

                std::vector 有一个带有两个迭代器的构造函数.你可以使用它:

                std::vector has a constructor that takes two iterators. You can use that:

                std::string str = "hello";
                std::vector<char> data(str.begin(), str.end());
                

                如果你已经有一个vector,并且想在最后添加字符,你需要一个back inserter:

                If you already have a vector and want to add the characters at the end, you need a back inserter:

                std::string str = "hello";
                std::vector<char> data = /* ... */;
                std::copy(str.begin(), str.end(), std::back_inserter(data));
                

                这篇关于如何将 std::string 复制到 std::vector<char> 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:boost asio 写/读向量 下一篇:“对"释放 std::vector 对象的方法

                相关文章

                最新文章

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

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

                    <legend id='a1MWM'><style id='a1MWM'><dir id='a1MWM'><q id='a1MWM'></q></dir></style></legend>
                    <tfoot id='a1MWM'></tfoot>