(6)string-子串

#include
#include
#include
using namespace std;

void test01()
{
	// 子串
	string str = "Hello";
	string Substr = str.substr(1, 3);
	cout << "Substr = " << Substr << endl;
}

// 实际操作
void test02()
{
	string email = "[email protected]";
	int pos = email.find("@");
	cout << "pos = " << pos << endl;

	//输出邮箱@前的信息
	string username = email.substr(0, pos);
	cout << "username = " << username << endl;
}
int main()
{
	//test01();
	test02();
	system("pause");
	return 0;
}

你可能感兴趣的:(c++)