[Solved] How to delete the book that have been input and how to make the title, language, and name doesn’t error if we put space on it? [closed]


If you want to enter data per line, here is an example:

class Book
{
    int number;
    int year;
    std::string language
    std::string name;
    std::string title;
  public:
    friend std::istream& operator>>(std::istream& input, Book& b);
//...
};

std::istream& operator>>(std::istream& input, Book& b)
{
  std::string text_line;
  std::getline(input, text_line);
  std::istringstream  text_stream(text_line);
  text_stream >> b.number >> b.year >> b.language >> b.name >> b.title;
  return input;
}

If each data item is on a separate line, you could change operator>> as:

std::istream& operator>>(std::istream& input, Book& b)
{
    input >> b.number;
    input >> b.year;
    std::getline(input, b.language);
    std::getline(input, b.name);
    std::getline(input, b.title);
    return input;
}

An example input from a file:

std::vector<Book> library;
Book b;
while (data_file >> b)
{
    library.push_back(b);
}

solved How to delete the book that have been input and how to make the title, language, and name doesn’t error if we put space on it? [closed]