🧸🧸🧸🧸🧸
  • 🧸's Blog
  • CodeJam
    • Kickstart Round H 2018 A Big Buttons
    • Kickstart Round H 2018 B Mural
  • C++/C
    • CashBox Code
    • for迭代数组
    • 字符串操作
    • 在函数中,int与int&的区别
    • sizeof()
    • memset的用法
    • 传值&传引用&传指针
    • STL
  • 经典算法
    • n皇后问题
  • Java
    • servlet从网址传入参数中文乱码
  • SQL
    • 左外连接与右外连接的区别
  • API
    • DeepGTAV v2
    • VPilot
    • SantosNet
    • deepdrive
    • iceb.link API
  • Spring Boot
    • Entity实体
    • 是否加@service的区别
    • Entity内字段表中名字不能为system
由 GitBook 提供支持
在本页
  • 删除字符串中某一项
  • 删除字符串第0项
  • 删除字符串第5项(从0开始)
  • 删除字符串第7项后8个字符串(从0开始)
  • 删除 从开头5个字符 到 倒数7个字符 之间的字符

这有帮助吗?

  1. C++/C

字符串操作

首先,

#include <string>

删除字符串中某一项

删除字符串第0项

#include <iostream>
#include <string>

int main ()
{
    std::string str ("This is an example sentence.");
    std::cout << str << '\n';
    str.erase(str.begin()+0);
    std::cout<<str;
    return 0;
}
This is an example sentence.
his is an example sentence.

删除字符串第5项(从0开始)

#include <iostream>
#include <string>

int main ()
{
    std::string str ("This is an example sentence.");
    std::cout << str << '\n';
    str.erase(str.begin()+5);
    std::cout<<str;
    return 0;
}
This is an example sentence.
This s an example sentence.

删除字符串第7项后8个字符串(从0开始)

#include <iostream>
#include <string>

int main ()
{
    std::string str ("This is an example sentence.");
    std::cout << str << '\n';
    str.erase (7,8);
    std::cout<<str;
    return 0;
}
This is an example sentence.
This isple sentence.

删除 从开头5个字符 到 倒数7个字符 之间的字符

#include <iostream>
#include <string>

int main ()
{
    std::string str ("This is an example sentence.");
    std::cout << str << '\n';
    str.erase (str.begin()+5, str.end()-7);
    std::cout<<str;
    return 0;
}
This is an example sentence.
This ntence.

上一页for迭代数组下一页在函数中,int与int&的区别

最后更新于6年前

这有帮助吗?