Hello everyone. I am trying to prompt the user for the title of a class course. For example, "Data Structures". I know I need to use the getline function, and I know how to use it. The problem I am having is when I use the getline command, it completely skips the input. Here is what I have:
string messagePrompt(string prompt)
{
//variable
string response;
bool good;
cin.clear();
//cin.ignore(200, '\n');
cout << "Please enter the students" << prompt;
cin >> response;
//getline(cin, response);
while (!good)
{
if (courseTitleValidate(response) == false)
{
cout << "INVALID ENTRY! All characters must be letters\n"
<< "Enter new course ID: ";
cin >> response;
}
else
good = true;
}
return response;
}
//**************************************************************************
//constant variable to display course title
const string COURSE_TITLE = " course title: ";
//****************************************************************************
void course::setCourseTitle1()
{
courseTitle = messagePrompt(COURSE_TITLE);
//cout << "course = " <<courseTitle<<endl;
}
//*******************************
//inside main. Calling this function to ask user for course title.
course3.setCourseTitle1(); //prompt user for course title
If I just use the cin and only input one word, it all works the way it should. When I uncomment the getline command, and input two or more words, it completely skips the user from inputting anything. I am not sure what I am doing wrong. Any help would be appreciated. Thank you.