当前位置:网站首页>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;
边栏推荐
- 【Batch】learning notes
- 用MLP代替掉Self-Attention
- Open3d learning note 3 [sampling and voxelization]
- C语言实现XML生成解析库(XML扩展)
- 【DIoU】《Distance-IoU Loss:Faster and Better Learning for Bounding Box Regression》
- 【DIoU】《Distance-IoU Loss:Faster and Better Learning for Bounding Box Regression》
- C语言的库函数
- 解决jetson nano安装onnx错误(ERROR: Failed building wheel for onnx)总结
- Where do you find the materials for those articles that have read 10000?
- What if a new window always pops up when opening a folder on a laptop
猜你喜欢
[multimodal] clip model
【学习笔记】Matlab自编高斯平滑器+Sobel算子求导
【Random Erasing】《Random Erasing Data Augmentation》
Income in the first month of naked resignation
Thesis writing tip2
The difference and understanding between generative model and discriminant model
C语言实现XML生成解析库(XML扩展)
简易打包工具的安装与使用
jetson nano安装tensorflow踩坑记录(scipy1.4.1)
静态库和动态库
随机推荐
【雙目視覺】雙目矯正
【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
One book 1078: sum of fractional sequences
MoCO ——Momentum Contrast for Unsupervised Visual Representation Learning
SQLyog远程连接centos7系统下的MySQL数据库
C # connect to MySQL database
【MobileNet V3】《Searching for MobileNetV3》
Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
Replace self attention with MLP
Where do you find the materials for those articles that have read 10000?
Network metering - transport layer
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
What if the laptop can't search the wireless network signal
Pointnet understanding (step 4 of pointnet Implementation)
C#与MySQL数据库连接
Sorting out dialectics of nature
Correction binoculaire
AR system summary harvest
[binocular vision] binocular stereo matching
業務架構圖