读书会报名时,用邮箱 @ 前面的那段当用户名:[email protected] 就是 amy。写 user_name(email);没有 @ 的,整个原样返回。
user_name("bao")→'bao'string user_name(const string &email)#include <string>
using namespace std;
string user_name(const string &email) {
auto at = email.find('@');
if (at == string::npos) {
// 在这里写:没找到 @,返回整个 email
}
// 在这里写:返回 @ 前面的那段
return "";
}
写好了先点「运行」试试示例,没问题再点「提交」。