Компилятор пропускает cin.getline

#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::getline;
using std::string;
using std::fstream;

class Book 
{
    string bookName;
    int bookAge = 0;

public:
    string GetBookName() { return bookName; }
    void SetBookName(string value) { bookName = value; }

    int GetBookAge() { return bookAge; }
    void SetBookAge(int value) { bookAge = value; }

    void PrintBook()
    {
        cout << "Имя книги: " << bookName << endl;
        cout << "Год выпуска книги: " << bookAge << endl;
        cout << endl;
    }
};

class Library
{
    Book* books;
    int size;

public:

    Library(int size)
    {
        books = new Book[size];
        this->size = size;
    }

    void WriteDataInLibrary() 
    {
        char name[60];
        int age;
        for (int i = 0; i < size; i++) 
        {
            cout << "Введите название книги" << endl;
            cin.getline(name, 60);
            cout << "Введите год выпуска книги" << endl;
            cin >> age;
            books[i].SetBookName(name);
            books[i].SetBookAge(age);
        }
    }

};

Компилятор в функции WriteDataInLibrary пропускает строчку cin.getline(...) Долго бьюсь с проблемой, но пока она побеждает меня всухую, прошу о помощи


Ответы (0 шт):