私のコードは、コンマで区切られた 2 つ以上の著者名を読み取り、最初の著者の姓を返す必要があります。
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
3 文字から 1 文字の長すぎるテキストが返されます。私のエラーへの洞察はありますか?