Possible Duplicate:
cin and getline skipping input
Please have a look at the following code
UIHandler.h
#pragma once
class UIHandler
{
public:
~UIHandler(void);
void bookAddWizard();
//static UIHandler *getInstance();
static UIHandler& getInstance();
private:
int bookCounter;
UIHandler();
};
UIHandler.cpp
#include "UIHandler.h"
#include <iostream>
using namespace std;
UIHandler::UIHandler()
{
{
}
}
UIHandler::~UIHandler(void)
{
}
UIHandler& UIHandler::getInstance()
{
static UIHandler uiHandler;
return uiHandler;
}
void UIHandler::bookAddWizard()
{
cout << endl << endl << endl;
cout << "..................Welcome to Book Adding Wizard................." << endl;
while(true)
{
if(bookCounter==10 || bookCounter>10)
{
cout << endl << endl;
cout << "Library is Full. No books will be accepted." << endl;
mainCaller();
break;
}
string id;
string bookName;
string auther;
string publisher;
string confirmation;
cout << endl;
cout << "Please enter Book ID: ";
//cin >> id;
getline(cin,id);
cout << endl;
cout << "Please enter Book Name: ";
//cin >> bookName;
getline(cin,bookName);
cout << "Please enter Auther's Name: ";
//cin >> auther;
getline(cin,auther);
cout << "Please enter publisher: ";
//cin >> publisher;
getline(cin,publisher);
books[bookCounter] = new Book();
books[bookCounter]->setAuther(auther);
books[bookCounter]->setBookName(bookName);
books[bookCounter]->setId(id);
books[bookCounter]->setPublisher(publisher);
books[bookCounter]->createCopy(bookCounter);
cout << "Book Added" << endl;
bookCounter++;
cout << bookCounter << endl;
cout << "Do you want to continue? Y/N: ";
cin >> confirmation;
if(confirmation=="Y" || confirmation=="y")
{
continue;
}
else
{
break;
}
}
}
here, for some reason, the getline function skips the first input. it do not display the cursor for the input, instead it simply comes to the second input! it is displayed in the image. please help