当前位置:网站首页>Erase method in string
Erase method in string
2022-07-02 08:00:00 【HBUcs2020】
1.
Put the starting position in the middle
Or starting position and number
#include<iostream>
#include<string>
using namespace std;
int main(){
string str = "hello c++! +++";
// From the position pos=10 Start deleting at , Until the end
// namely : " +++"
str.erase(10);
cout << '-' << str << '-' << endl;
// From the position pos=6 Start at , Delete 4 Characters
// namely : "c++!"
str.erase(6, 4);
cout << '-' << str << '-' << endl;
return 0;
}
2.
iterator [ )
#include<iostream>
#include<string>
using namespace std;
int main(){
string str = "hello c++! +++";
// Delete "+++" One space before
str.erase(str.begin()+10);
cout << '-' << str << '-' << endl;
// Delete "+++"
str.erase(str.begin() + 10, str.end());
cout << '-' << str << '-' << endl;
return 0;
}
3. Single character of iterator position
iterator erase(const_iterator position)
Delete a single character at the iterator position , And back to Next element
The iterator
4.pop_back(): Delete the last element
5. Often with find Functions together
string longer("That's a funny hat.");
//size_type loc1 = longer.find("hat"); // There is
size_type loc1 = longer.find("hello"); // non-existent
if (loc1 == string::npos)
cout<< "not found" <<endl;
边栏推荐
- 【MobileNet V3】《Searching for MobileNetV3》
- WCF更新服务引用报错的原因之一
- On the confrontation samples and their generation methods in deep learning
- 【Batch】learning notes
- 静态库和动态库
- Several methods of image enhancement and matlab code
- 使用C#语言来进行json串的接收
- Organigramme des activités
- 【AutoAugment】《AutoAugment:Learning Augmentation Policies from Data》
- 【双目视觉】双目立体匹配
猜你喜欢
【Cascade FPD】《Deep Convolutional Network Cascade for Facial Point Detection》
【Batch】learning notes
Several methods of image enhancement and matlab code
应对长尾分布的目标检测 -- Balanced Group Softmax
Embedding malware into neural networks
Vscode下中文乱码问题
【学习笔记】Matlab自编图像卷积函数
On the confrontation samples and their generation methods in deep learning
【雙目視覺】雙目矯正
CVPR19-Deep Stacked Hierarchical Multi-patch Network for Image Deblurring论文复现
随机推荐
静态库和动态库
Open3D学习笔记一【初窥门径,文件读取】
Rhel7 operation level introduction and switching operation
(15) Flick custom source
【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
MoCO ——Momentum Contrast for Unsupervised Visual Representation Learning
Label propagation
MySQL优化
Dynamic extensible representation for category incremental learning -- der
【C#笔记】winform中保存DataGridView中的数据为Excel和CSV
One book 1078: sum of fractional sequences
SQLyog远程连接centos7系统下的MySQL数据库
[binocular vision] binocular stereo matching
CVPR19-Deep Stacked Hierarchical Multi-patch Network for Image Deblurring论文复现
Embedding malware into neural networks
【Cascade FPD】《Deep Convolutional Network Cascade for Facial Point Detection》
Gensim如何冻结某些词向量进行增量训练
Brief introduction of prompt paradigm
TimeCLR: A self-supervised contrastive learning framework for univariate time series representation
【MagNet】《Progressive Semantic Segmentation》