ユーザーから何もキャプチャしない次の方法があります。アーティスト名にNewBandを入力すると、「New」のみがキャプチャされ、「Band」は省略されます。代わりにcin.getline()を使用すると、何もキャプチャされません。これを修正する方法はありますか?
char* artist = new char [256];
char * getArtist()
{
cout << "Enter Artist of CD: " << endl;
cin >> artist;
cin.ignore(1000, '\n');
cout << "artist is " << artist << endl;
return artist;
}
これはうまくいきました。ありがとうロジャー
std::string getArtist()
{
cout << "Enter Artist of CD: " << endl;
while(true){
if ( getline(cin, artist)){
}
cout << "artist is " << artist << '\n';
}
return artist;
}