1. <tfoot id='S9g3s'></tfoot><legend id='S9g3s'><style id='S9g3s'><dir id='S9g3s'><q id='S9g3s'></q></dir></style></legend>

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

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

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

        递归地传递一个字符串而不需要娱乐

        时间:2023-08-03

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

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

                  <tbody id='ObavJ'></tbody>
                  <bdo id='ObavJ'></bdo><ul id='ObavJ'></ul>
                  <tfoot id='ObavJ'></tfoot>
                • 本文介绍了递归地传递一个字符串而不需要娱乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在这里回答了一个问题:https://stackoverflow.com/a/28862668/2642059我需要在哪里使用重复来遍历 string.我想在每个函数上使用 const string& 作为我的参数,但是除非我想在每次递归时重建字符串,否则我发现我需要传递一个 startfinish 位置以及 string 本身.所以传递 string 变得毫无意义.

                  I answered a question here: https://stackoverflow.com/a/28862668/2642059 Where I needed to use recurrence to step through a string. I wanted to use a const string& as my parameter on each function, but unless I wanted to reconstruct the string each recursion I found that I needed to pass a start and finish position as well as the string itself. So it became pointless to pass the string at all.

                  最后我选择只将 startfinish 指针传递给 char[].

                  In the end I choose to just pass a start and finish pointer to the char[].

                  举个例子,假设我得到一个包含嵌套括号的字符串(但没有并排插入括号.)就像这样:

                  As an example, say that I'm given a string which contains nested parenthesis (but no side by side parenthetical insertions.) So like this:

                  (abc(def(ghi((j)klm)nop)qrs)tuv)wxyz

                  (abc(def(ghi((j)klm)nop)qrs)tuv)wxyz

                  但不是这样:

                  (abc(def)(ghi)(j)(klm)(nop)(qrs)tuv)wxyz

                  (abc(def)(ghi)(j)(klm)(nop)(qrs)tuv)wxyz

                  我想编写一个递归程序来提取最深嵌套括号中的字符串.类似的东西:

                  I want to write a recursive program to extract the string in the deepest nested parentheses. Something like:

                  string foo(const string& bar){
                      auto start = bar.find('(') + 1;
                  
                      return start == string::npos + 1 ? bar : foo(bar.substr(start, bar.find_last_of(')') - start));
                  }
                  

                  然而,我不高兴为 foo 的每次重复重建一个 string.另一种方法是像链接示例中一样传递 startfinish 指针(或传递 string::const_iterators.)

                  However I'm unhappy reconstructing a string for each recurrence of foo. The alternative is to pass start and finish pointers as in the linked example (or to pass string::const_iterators.)

                  是否有包装器或其他东西可以让我使用 string 功能,但不能重建 string?

                  Is there a wrapper or something which would allow me to use string functionality, but not reconstruct a string?

                  推荐答案

                  string_view 来自库基础知识 TS 可能是一个想法,在 GCC 中提供支持.

                  string_view from the library fundamentals TS might be one idea, support is available in GCC.

                  接口实际上与string

                  #include <experimental/string_view>
                  using std::experimental::string_view;
                  
                  string_view foo(const string_view& bar){
                      auto start = bar.find('(') + 1;
                  
                      return start == string_view::npos + 1 ? bar : foo(bar.substr(start, bar.find_last_of(')') - start));
                  }
                  

                  最后一行也可以

                  return start ? foo(bar.substr(start, bar.find_last_of(')') - start)) : bar;
                  

                  虽然它们都很神秘.

                  这篇关于递归地传递一个字符串而不需要娱乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 C++ MFC 进行递归文件搜索? 下一篇:给定一个正则表达式,我将如何生成与之匹配的

                  相关文章

                  最新文章

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

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

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

                    2. <tfoot id='y6LL7'></tfoot>