#include<bits/stdc++.h>
using namespace std;
int main(){
//分割 字符串
string s = "1234" ;
//substr(起点,数量(一共需要截取个数))
//substr(i, count)
//如果个数量很大,或者省略,自动截取到字符串的末尾
// cout << s.substr(3 , 1212) ;
// for(int i=0; i<3; i++){
// cout << s.substr(0, i+1) ;
// cout << "+";
// cout << s.substr(i+1);
// cout << endl ;
// }
// stoi 用字符串转成int类型整数
// stoll 用字符串转成long long类型的整数
string a="1234545455454" , b ="223";
cout << stoll(a)+ stoll(b) << endl;
//查找find()查找某个字符串的位置
//如果找到则返回对应的下标位置
//如果找不到则返回long long类型最大值,我们强制转int变成-1
string ss = "1112=44" ;
cout << (int)ss.find("x") << endl;
//替换replace()替换其中的某些字符串
// replace(i, count, "xx") i表示需要替换的起点 count长度 xx表示需要替换的值
ss.replace(4,1,"++");
cout << ss <<endl ; //ss=1112++44
//插入insert()向某个位置插入某些字符串
ss.insert(1,"www");
cout << ss << endl ; //ss=1www112++44
//删除erase()
//erase(i,count) 删除从i开始的count个字符串
//如果说count省略或者这个值很大,自动删除到末尾
ss.erase(1, 3);
cout << ss << endl ; //ss=1112++44
return 0;
}
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com