C++删除字符串中指定位子或者指定字符或字符串的函数。

 我来答
hwd0312
2015-10-21 · TA获得超过4336个赞
知道小有建树答主
回答量:1043
采纳率:100%
帮助的人:162万
展开全部

C++中字符串删除函数为 std::string::erase 有三种形式:

sequence (1)   string& erase (size_t pos = 0, size_t len = npos);

character (2)   iterator erase (iterator p);

range (3)         iterator erase (iterator first, iterator last);

示例:

// string::erase
#include <iostream>
#include <string>

int main ()
{
  std::string str ("This is an example sentence.");
  std::cout << str << '\n';
                                           // "This is an example sentence."
  str.erase (10,8);                        //  (1)          ^^^^^^^^
  std::cout << str << '\n';
                                           // "This is an sentence."
  str.erase (str.begin()+9);               //    (2)        ^
  std::cout << str << '\n';
                                           // "This is a sentence."
  str.erase (str.begin()+5, str.end()-9);  //     (3)   ^^^^^
  std::cout << str << '\n';
                                           // "This sentence."
  return 0;
}

    结果:

This is an example sentence.
This is an sentence.
This is a sentence.
This sentence.
妙妙系列溥VL
2015-09-18 · TA获得超过186个赞
知道答主
回答量:181
采纳率:100%
帮助的人:112万
展开全部
C++中的string类中有erase成员函数,其功能是删除字符串中的字符或字符串。 该成员函数的原型为 string erase(int start, int len); //start为要删除字符的起始位置(从0数起),len为要删除字符的个数。
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式