网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
int compare(const string &s) const;
与字符串s比较int compare(const char*s) const;
与字符串s比较
1.3 代码展示
- 左=右时
- 左>右时
- 左<右时
- 代码
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
void text01() {
//字符串的比较(类似于C里的strcmp()函数)
string s1 = "hello";
string s2 = "helpo";
if (s1.compare(s2) == 0) {
cout << "s1=s2" << endl;
}
else if (s1.compare(s2) > 0) {
cout << "s1>s2" << endl;
}
else {
cout << "s1<s2" << endl;
}
}
int main() {
text01();
return 0;
}
2. 字符读写
2.1 字符读入/访问
2.1.1 方式
- 通过
[]
下标访问 - 通过
.at()
访问
2.1.2 代码展示
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
//字符串的存取
//访问修改单个字符
void text01() {
//法①:通过 [] 访问单个字符
string s1 = "hello";
int len = s1.size();
for (int i = 0; i < len; i++) {
cout << s1[i] << " ";
}
cout << endl;
//法②:通过at方式访问单个字符
for (int i = 0; i < len; i++) {
cout << s1.at(i) << " ";
}
cout << endl;
}
int main() {
text01();
return 0;
}
2.2 修改字符
2.2.1 方式
- 使用下标
[]
直接修改 - 使用
.at()
进行修改
2.2.2 代码展示
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
//字符串的存取
//修改单个字符
void text02() {
//法①:通过[]来修改
string s1 = "hello";
s1[0] = 'p';
cout << s1 << endl;
//法②:通过s1.at()来修改
s1.at(1) = 'q';
cout << s1 << endl;
}
int main() {
//text01();
text02();
return 0;
}
3. 插入和删除
3.1 函数原型
string& insert(int pos, const char*s)
插入字符串string& insert(int pos, const string& str);
插入字符串string& insert(int pos, int n, char c);
在指定位置插入n个字符cstring& erase(int pos,int n = npos);
从pos开始删除n个字符
3.2 代码展示
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
//插入操作
void text01() {
string s1 = "hello";
s1.insert(1, "123");
//从下标为1开始,插入"123"
cout << s1 << endl;
}
void text02() {
string s1 = "h123ello";
s1.erase(1, 3);
//从坐标为1开始,删除3个字符
cout << s1 << endl;
}
int main() {
text01();
text02();
return 0;
}
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!**
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新