标准库的string有一个substr函数用来截取子字符串。一般使用时传入两个参数,第一个是开始的坐标(第一个字符是0),第二个是截取的长度
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s=“123456”;
string first(s.substr(2,3));
cout<<first;//345
return 0;
}
截取字符串
最新推荐文章于 2023-08-14 14:07:45 发布