目录

erase

描述 (Description)

它擦除部分字符串,减少其长度。

声明 (Declaration)

以下是std :: string :: erase的声明。

string& insert (size_t pos, const string& str);

C++11

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

C++14

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

参数 (Parameters)

  • pos - 这是一个插入点。

  • str - 它是一个字符串对象。

  • len - 它包含有关要删除的字符数的信息。

返回值 (Return Value)

它返回* this。

异常 (Exceptions)

如果抛出异常,则字符串中没有变化。

例子 (Example)

在下面的示例中为std :: string :: erase。

#include <iostream>
#include <string>
int main () {
   std::string str ("sairamkrishna Mammahe is a one of the tech person.");
   std::cout << str << '\n';
   str.erase (10,8);
   std::cout << str << '\n';
   str.erase (str.begin()+9);
   std::cout << str << '\n';
   str.erase (str.begin()+5, str.end()-9);
   std::cout << str << '\n';
   return 0;
}

样本输出应该是这样的 -

sairamkrishna Mammahe is a one of the tech person.
sairamkrisahe is a one of the tech person.
sairamkriahe is a one of the tech person.
sairah person.
↑回到顶部↑
WIKI教程 @2018