string中删除操作,基于STL

#include <stdio.h>
#include <string>
#include <iostream>
#include <cstddef>//标准库中size_t 定义
using namespace  std;



int main(int argc,char * argv[])
{

string a="www.baidu.com/name/location";
string b="www.baidu.com/location/hang";
string delete_str="www.baidu.com/";
size_t index=a.find(delete_str);
if(index!=string::npos)//find找不到位置时,会返回npos
cout<<a.erase(index,delete_str.length())<<endl;
//.erase 成员函数 index表示要删除的串的位置地址,删除的长度,返回删除后的串的指针

猜你喜欢

转载自blog.csdn.net/qq_36184671/article/details/81840535