随笔分类 -  string容器

摘要:功能描述: 从字符串中获取想要的子串 函数原型: string substr(int pos = 0, int n = npos) const; //返回由pos开始的n个字符组成的字符串 1 #include <iostream> 2 #include <string> 3 using names 阅读全文
posted @ 2020-07-09 13:08 坦率 阅读(165) 评论(0) 推荐(0)
摘要:功能描述: 对string字符串进行插入和删除字符操作 函数原型: string& insert(int pos, const char* s); //插入字符串 string& insert(int pos, const string& str); //插入字符串 string& insert(i 阅读全文
posted @ 2020-07-09 12:16 坦率 阅读(173) 评论(0) 推荐(0)
摘要:string中单个字符存取方式有两种 char& operator[](int n); //通过[]方式取字符 char& at(int n); //通过at方法获取字符 1 #include <iostream> 2 #include <string> 3 using namespace std; 阅读全文
posted @ 2020-07-09 12:04 坦率 阅读(245) 评论(0) 推荐(0)
摘要:功能描述: 字符串之间的比较 比较方式: 字符串比较是按字符的ASCII码进行对比 = 返回 0 > 返回 1 < 返回 -1 函数原型: int compare(const string &s) const; //与字符串s比较 int compare(const char *s) const;  阅读全文
posted @ 2020-07-09 11:47 坦率 阅读(243) 评论(0) 推荐(0)
摘要:功能描述: 查找:查找指定字符串是否存在 替换:在指定的位置替换字符串 函数原型: int find(const string& str,int pos = 0) const; //查找str第一次出现位置,从pos开始查找 int find(const char* s,int pos = 0) c 阅读全文
posted @ 2020-07-09 11:20 坦率 阅读(268) 评论(0) 推荐(0)
摘要:功能描述: 实现在字符串末尾拼接字符串 函数原型: string& operator+=(const char* str); //重载+=操作符 string& operator+=(const char c); //重载+=操作符 string& operator+=(const string& 阅读全文
posted @ 2020-07-09 11:05 坦率 阅读(515) 评论(0) 推荐(0)
摘要:功能描述: 给string字符串进行赋值 赋值函数原型: string& operator=(const char *s); //char*类型字符串 赋值给当前的字符串 string& operator=(const string &s); //把字符串s赋给当前的字符串 string& oper 阅读全文
posted @ 2020-04-29 17:19 坦率 阅读(589) 评论(0) 推荐(0)
摘要:************************************************************************************************ 本质: string是典型的C++风格的字符串,而string本质上是一个类 string 和 char 阅读全文
posted @ 2020-04-29 16:50 坦率 阅读(182) 评论(0) 推荐(0)
摘要:学习目标: 容器嵌套容器,我们将所有的数据进行遍历输出 1 #include <iostream> 2 #include <string> 3 #include <vector> 4 using namespace std; 5 6 //vector容器嵌套容器 7 void test_01(voi 阅读全文
posted @ 2020-04-29 16:27 坦率 阅读(1602) 评论(0) 推荐(0)
摘要:学习目标: vector存放自定义数据类型,并打印输出 解引用: 1 #include <iostream> 2 #include <string> 3 #include <vector> 4 using namespace std; 5 6 //vector存放自定义数据类型 7 class Pe 阅读全文
posted @ 2020-04-29 10:51 坦率 阅读(1586) 评论(0) 推荐(0)
摘要:容器:vector 算法:for_each 迭代器:vector<int>::iterator 1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 using namespace std; 5 6 //为第三种遍历方式 阅读全文
posted @ 2020-04-28 17:24 坦率 阅读(408) 评论(0) 推荐(0)
摘要:STL:Standard Template Library. STL:从广义上划分为:容器(container [kənˈteɪnər])、算法(algorithm [ˈælgəˌrɪðəm])、迭代器(iterator [ɪtə'retɚ]) 容器和算法之间通过迭代器进行无缝对接 STL六大组件: 阅读全文
posted @ 2020-04-28 17:22 坦率 阅读(126) 评论(0) 推荐(0)