当前位置:网站首页>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;
边栏推荐
猜你喜欢
联邦学习下的数据逆向攻击 -- GradInversion
[multimodal] clip model
【Cascade FPD】《Deep Convolutional Network Cascade for Facial Point Detection》
Network metering - transport layer
【学习笔记】Matlab自编图像卷积函数
Sequence problem for tqdm and print
w10升级至W11系统,黑屏但鼠标与桌面快捷方式能用,如何解决
Target detection for long tail distribution -- balanced group softmax
[learning notes] matlab self compiled image convolution function
open3d学习笔记四【表面重建】
随机推荐
Feature Engineering: summary of common feature transformation methods
【Cascade FPD】《Deep Convolutional Network Cascade for Facial Point Detection》
Gensim如何冻结某些词向量进行增量训练
Thesis tips
Several methods of image enhancement and matlab code
Jetson nano installation tensorflow stepping pit record (scipy1.4.1)
【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
JVM instructions
Embedding malware into neural networks
关于原型图的深入理解
Look for we media materials from four aspects to ensure your creative inspiration
使用C#语言来进行json串的接收
open3d学习笔记四【表面重建】
In the era of short video, how to ensure that works are more popular?
open3d学习笔记五【RGBD融合】
Where do you find the materials for those articles that have read 10000?
【Mixed Pooling】《Mixed Pooling for Convolutional Neural Networks》
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
用于类别增量学习的动态可扩展表征 -- DER
[multimodal] clip model