• <bdo id='7OmUD'></bdo><ul id='7OmUD'></ul>

    <tfoot id='7OmUD'></tfoot>
        <legend id='7OmUD'><style id='7OmUD'><dir id='7OmUD'><q id='7OmUD'></q></dir></style></legend>
      1. <small id='7OmUD'></small><noframes id='7OmUD'>

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

        C++ std::transform() 和 toupper() ..为什么会失败?

        C++ std::transform() and toupper() ..why does this fail?(C++ std::transform() 和 toupper() ..为什么会失败?)
      3. <small id='f3crS'></small><noframes id='f3crS'>

          <tbody id='f3crS'></tbody>

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

          • <tfoot id='f3crS'></tfoot>
            • <bdo id='f3crS'></bdo><ul id='f3crS'></ul>
                1. 本文介绍了C++ std::transform() 和 toupper() ..为什么会失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有 2 个 std::string.我只想,给定输入字符串:

                  I have 2 std::string. I just want to, given the input string:

                  1. 大写每个字母
                  2. 将大写字母分配给输出字符串.

                  这是如何工作的:

                    std::string s="hello";
                    std::string out;
                    std::transform(s.begin(), s.end(), std::back_inserter(out), std::toupper);
                  

                  但这不会(导致程序崩溃)?

                  but this doesn't (results in a program crash)?

                    std::string s="hello";
                    std::string out;
                    std::transform(s.begin(), s.end(), out.begin(), std::toupper);
                  

                  因为这有效(至少在同一个字符串上:

                  because this works (at least on the same string:

                    std::string s="hello";
                    std::string out;
                    std::transform(s.begin(), s.end(), s.begin(), std::toupper);
                  

                  推荐答案

                  out 中没有空格.C++ 算法不会自动增长其目标容器.您必须自己腾出空间,或者使用插入式适配器.

                  There is no space in out. C++ algorithms do not grow their target containers automatically. You must either make the space yourself, or use a inserter adaptor.

                  要在 out 中腾出空间,请执行以下操作:

                  To make space in out, do this:

                  out.resize(s.length());

                  [edit] 另一种选择是使用此构造函数创建具有正确大小的输出字符串.

                  [edit] Another option is to create the output string with correct size with this constructor.

                  std::string out(s.length(), 'X');

                  这篇关于C++ std::transform() 和 toupper() ..为什么会失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  How should a size-limited stl-like container be implemented?(应该如何实现大小受限的 stl 类容器?)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  <tfoot id='wIdWd'></tfoot>

                      <bdo id='wIdWd'></bdo><ul id='wIdWd'></ul>
                    • <small id='wIdWd'></small><noframes id='wIdWd'>

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