<tfoot id='hl8gx'></tfoot>

    <legend id='hl8gx'><style id='hl8gx'><dir id='hl8gx'><q id='hl8gx'></q></dir></style></legend>

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

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

      如何删除c ++字符串中所有出现的字符

      How to remove all the occurrences of a char in c++ string(如何删除c ++字符串中所有出现的字符)
      • <bdo id='xPmCE'></bdo><ul id='xPmCE'></ul>
        <legend id='xPmCE'><style id='xPmCE'><dir id='xPmCE'><q id='xPmCE'></q></dir></style></legend>
          <tfoot id='xPmCE'></tfoot>
        1. <i id='xPmCE'><tr id='xPmCE'><dt id='xPmCE'><q id='xPmCE'><span id='xPmCE'><b id='xPmCE'><form id='xPmCE'><ins id='xPmCE'></ins><ul id='xPmCE'></ul><sub id='xPmCE'></sub></form><legend id='xPmCE'></legend><bdo id='xPmCE'><pre id='xPmCE'><center id='xPmCE'></center></pre></bdo></b><th id='xPmCE'></th></span></q></dt></tr></i><div id='xPmCE'><tfoot id='xPmCE'></tfoot><dl id='xPmCE'><fieldset id='xPmCE'></fieldset></dl></div>

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

              <tbody id='xPmCE'></tbody>

                本文介绍了如何删除c ++字符串中所有出现的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用以下内容:

                replace (str1.begin(), str1.end(), 'a' , '')
                

                但这会导致编译错误.

                推荐答案

                基本上,replace 将一个字符替换为另一个字符,而 '' 不是一个字符.你要找的是erase.

                Basically, replace replaces a character with another and '' is not a character. What you're looking for is erase.

                参见 这个问题,它回答了同样的问题.在你的情况下:

                See this question which answers the same problem. In your case:

                #include <algorithm>
                str.erase(std::remove(str.begin(), str.end(), 'a'), str.end());
                

                或者使用 boost 如果这是您的选择,例如:

                Or use boost if that's an option for you, like:

                #include <boost/algorithm/string.hpp>
                boost::erase_all(str, "a");
                

                所有这些都在 reference 网站.但是如果你不知道这些功能,你可以很容易地手工完成这种事情:

                All of this is well-documented on reference websites. But if you didn't know of these functions, you could easily do this kind of things by hand:

                std::string output;
                output.reserve(str.size()); // optional, avoids buffer reallocations in the loop
                for(size_t i = 0; i < str.size(); ++i)
                  if(str[i] != 'a') output += str[i];
                

                这篇关于如何删除c ++字符串中所有出现的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                Adding types to the std namespace(将类型添加到 std 命名空间)
                Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)

                <tfoot id='fnoCn'></tfoot>

              • <legend id='fnoCn'><style id='fnoCn'><dir id='fnoCn'><q id='fnoCn'></q></dir></style></legend>

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

                  <tbody id='fnoCn'></tbody>

                        <bdo id='fnoCn'></bdo><ul id='fnoCn'></ul>
                        1. <small id='fnoCn'></small><noframes id='fnoCn'>