![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
STL
qxq_sunshine
持之以恒
展开
-
STL——string字符串的插入和删除、子串的功能
代码实现:#include<iostream>#include<string>using namespace std;//字符串的插入和删除void test01(){ string str1 = "hello"; //字符串的插入 str1.insert(1, "111");//从第一个位置起,插入111 cout << "str1=" <<str1<< endl; //字符串的删除 str1.erase(1, 3原创 2021-05-07 17:14:23 · 748 阅读 · 0 评论 -
STL——string字符串比较、字符存取
一、string字符串比较功能描述:字符串之间的比较比较方式:字符串是按照ASCII码进行比较的,=返回0>返回1<返回-1函数原型:int compare(const string &s) const; //与字符串s比较int compare(const char *s) const; //与字符串s比较Demo:#include<iostream>#include<string>using namespa原创 2021-05-07 16:17:02 · 1181 阅读 · 0 评论 -
STL——string查找和替换
功能描述:查找:查找指定的字符串是否存在替换:在指定位置替换字符串函数原型:* int find(const string& str, int pos=0) const;//查找str第一次出现的位置,从pos位置开始查找* int find(const char*s, int pos=0) const; //查找字符c第一次出现的位置,从pos的位置开始查找* int find(const char*s, int pos, int n) const; //从pos的位置开始查找原创 2021-05-07 16:00:32 · 744 阅读 · 0 评论 -
STL——string的赋值操作
功能:给string字符串进行赋值 string字符串拼接操作赋值的函数原型:共有2种,分别为operate=和assign两种。string& operator=(const char *s); //char*类型字符串 赋值给当前的字符串string& operator=(const string *s); //把当前的字符串s赋值给当前的字符串string& operator=(char c); //字符赋值给当前的字符串string& ass原创 2021-05-07 13:39:35 · 1360 阅读 · 0 评论 -
STL——String
一、基本概念1、string是C++风格的字符串,而string本质是一个类2、string和char*的区别:char*是一个指针string是一个类,类内部封装了char*,管理这个字符串,是一个char*型的容器3、特点:string类内部封装了很多成员方法如,查找find,拷贝copy,删除delete,替换replace,插入insert4、string管理char*所分配的内存,不用担心复制越界和取值越界等,由类内部进行负责。二、基本操作构造函数原型:原创 2021-05-07 11:07:59 · 88 阅读 · 0 评论 -
C++——迭代器
Vector可理解为数组容器:vector算法:for_each迭代器:vector<int>::iterator小demo:#include <iostream>#include<vector>#include<algorithm>using namespace std;void myPrint(int val){ cout << val << endl;}void test01()原创 2021-05-06 22:55:51 · 121 阅读 · 0 评论 -
C++——模板基本概念
1、C++的另一种编程思想称为 泛型编程, 利用 的技术是模板C++提供了两种模板机制:函数模板和类模板2、函数模板的作用建立一个通用的函数,其函数返回值和形参类型可以不具体制定,用一个虚拟的类型来代表。语法: template <typename T>----template:声明创建模板;----typename:表明后面的符号是一种类型,可以用class代替。—T: 通用的数据类型,名称可以替换,通常为大写字母示例:...原创 2021-03-23 09:57:52 · 181 阅读 · 0 评论