Know, tell me what the error is. Such a task is set, it is necessary to implement the interface of the home audio collection, created it so

struct Songs { char name_autor[50]; char name_song[50]; double time; }; class Audio_Collection { public: Songs audio[N]; void set_audio(); void print_audio(); void sort_name_autor(); void sort_name_song(); void sort_time(); }; 

Here is the implementation of f-ii data entry,

 void Audio_Collection::set_audio() { for (int i = 0; i < N; i++) { cout << "Введите имя автора(группы): "; cin.getline(audio[i].name_autor, 50); cout << "Введите название песни: "; cin.getline(audio[i].name_song, 50); cout << "Введите продолжительность трека: "; cin >> audio[i].time; } } 

And here's the catch, when entering data, this error occurs enter image description here

When you enter the second subsequent values, the string is not executed.

 cin.getline(audio[i].name_autor, 50); 

How to fix it?

Reported as a duplicate by Harry c ++ 11 Feb '17 at 15:30 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

1 answer 1

Flush the buffer after reading a double - there is a newline in it ... Add after

 cin >> audio[i].time; 

line

 cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');