#include<iostream>
#include<string>
using namespace std;
//string从字符串中得到想要的子串
void test1() {
string str;
str = "hello";
cout << str << endl;
//从str第一个开始截取三个字符
string Substr=str.substr(1, 3);
cout << Substr << endl;
}
void test2() {
string str1 = "liming@sano.com";
//找到'a'的下标位置8
int pos = str1.find('@');
string Substr1 = str1.substr(0, pos);
cout << Substr1 << endl;
}
int main() {
test1();
test2();
system("pause");
return 0;
}
string从字符串中得到想要的字串
最新推荐文章于 2023-02-11 09:12:59 发布