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

  • <tfoot id='dk1cQ'></tfoot>

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

    2. <small id='dk1cQ'></small><noframes id='dk1cQ'>

      1. 如何最优雅地获取 std::vector 缓冲区的地址开始

        时间:2023-09-15

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

              <tbody id='lOfBK'></tbody>

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

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

                • 本文介绍了如何最优雅地获取 std::vector 缓冲区的地址开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想使用 std::vector 来动态分配内存.场景是:

                  I want to use std::vector for dynamically allocating memory. The scenario is:

                  int neededLength = computeLength(); // some logic here
                  
                  // this will allocate the buffer     
                  std::vector<TCHAR> buffer( neededLength );
                  
                  // call a function that accepts TCHAR* and the number of elements
                  callFunction( &(buffer[0]), buffer.size() );
                  

                  上面的代码有效,但是这个 &(buffer[0]) 看起来很难看.有没有更优雅的方法来实现相同的目标?

                  The code above works, but this &(buffer[0]) looks ugly. Is there a more elegant way to achieve the same?

                  推荐答案

                  好吧,你可以删除一组括号:

                  Well, you can remove one set of parens:

                  &buffer[0]
                  

                  但这是常见的、惯用的方式.如果它真的冒犯了您,我想您可以使用模板 - 类似于:

                  but that is the common, idiomatic way of doing it. If it really offends you, I suppose you could use a template - something like:

                  template <typename T> 
                  T * StartOf( std::vector <T> & v ) {
                      return &v[0];
                  }
                  

                  这篇关于如何最优雅地获取 std::vector 缓冲区的地址开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:向量的小字符串优化? 下一篇:std::vector 到带有自定义分隔符的字符串

                  相关文章

                  最新文章

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

                    <small id='1mtzZ'></small><noframes id='1mtzZ'>

                  2. <tfoot id='1mtzZ'></tfoot>