我的代码应该读取两个或多个作者姓名,用逗号分隔,然后返回第一作者的姓氏。
cout << "INPUT AUTHOR: " << endl ;
getline(cin, authors, '\n') ;
int AuthorCommaLocation = authors.find(",",0) ;
int AuthorBlankLocation = authors.rfind(" ", AuthorCommaLocation) ;
string AuthorLast = authors.substr(AuthorBlankLocation+1, AuthorCommaLocation-1) ;
cout << AuthorLast << endl ;
但是,当我尝试检索AuthorLast
子字符串时,它返回的文本从三到一个字符过长。对我的错误有任何见解吗?