C++ string之erase()

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;
const int maxn = 1e6 + 100;

int main() {
	string str;
	for(int i = 'a'; i <= 'z'; i++)
		str += i;
	str.erase(10);//刪除下標爲 10 及其之後的所有字符 
	str.erase(1, 2);//從下標 10 開始刪除兩個字符 
	str.erase(str.begin());//刪除 下標爲 0 的字符 
	str.erase(str.begin(), str.end() - 2); //刪除在[str.begin(), str.end() - 1) 區間內的所有字符 
	cout << str;
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章