But if I copy and paste the same line so that it looks like:
getline(cin,title); getline(cin,title);
The program skips only the first getline, the second getline runs fine.
Don't know what's the problem, so I hope you guys can help me figure it out.
Here's the code, I deleted all the unnecessary stuffs to make it easier for you guys to keep track.
#include <iostream>
#include <string>
using namespace std;
const int MAX = 10;
class Book
{
private:
string title;
public:
Book();
void setTitle();
};
int main()
{
int i, size;
Book books[MAX];
cout << "Enter the number of book entries: ";
cin >> size;
cout << endl;
for (i = 0; i < size; i++)
{
books[i].setTitle();
cout << endl;
}
}
Book::Book()
{
}
void Book::setTitle()
{
cout << "\nEnter the book title: ";
getline(cin,title);
}

New Topic/Question
Reply



MultiQuote



|