重複の可能性:
cinとgetlineが入力をスキップする
次のコードをご覧ください
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;
}
}
}
ここで、何らかの理由で、getline関数は最初の入力をスキップします。入力用のカーソルは表示されません。代わりに、2番目の入力に移動します。画像に表示されます。助けてください