小工具知识网

当前位置: 首页 > 行业知识 > 【C++ STL】string类最全解析(什么是string?string类的常用接口有哪些?)

行业知识

【C++ STL】string类最全解析(什么是string?string类的常用接口有哪些?)

2026-11-10 13:45:09 来源:互联网转载

目录

一、前言

 二、什么是 string ?

  string 类的基本概念

string 类与 char * 的区别 

  string 类的作用

  总结

 三、string 的常用接口详解

 string 类对象的默认成员函数

① 构造函数(初始化)

② 赋值重载(初始化)

string 类对象的访问及遍历操作

① operator[ ] (⭐)

② at 

③ 迭代器 (⭐)

④ 范围for 

 string 类对象的常见容量操作

 ①  size、length、capacity

 ② clear

 ③ empty

 ④ reserve (⭐)

 ⑤ resize (⭐)

 ⑥ 【reserve】和【resize】在使用中的易错点 (⭐)

string类对象的修改操作

 ① push_back

 ② append 

 ③ operator+=(string) (⭐)

 ④ insert (⭐)

 ⑤ assign 

 ⑥ erase (⭐)

 ⑦ replace 

 ⑧ pop_back 

 ⑨ swap

string类对象的其他字符串操作

① c_str

② substr (⭐)

③ find (⭐)

例题训练:分割url

④ rfind

⑤ find_first_of

⑥ find_last_of

⑦ find_first_not_of 

⑧ find_last_not_of 

 string类对象的非成员函数重载

① operator+ () 

② relational operators 

③ operator>>()

④ operator

上一篇:前端手册-实现挂坠灯笼效果

下一篇:pingdom怎么用?