substr用法: s.substr(i,j)表示从下标为i的位置开始截取j位。
#include<string>
#include<iostream>
using namespace std;
int main()
{
string s("12345asdf");
string a=s.substr(0,5);
cout<<a<<endl;
}
上述代码获得字符串a为从第0位开始的长度为5的字符串
输出结果为: 12345
substr用法: s.substr(i,j)表示从下标为i的位置开始截取j位。
#include<string>
#include<iostream>
using namespace std;
int main()
{
string s("12345asdf");
string a=s.substr(0,5);
cout<<a<<endl;
}
上述代码获得字符串a为从第0位开始的长度为5的字符串
输出结果为: 12345