getline function

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:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  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.
Remove cin>>response and then uncomment getline.
I did that. That is when it completely skips the user from inputting anything
1
2
string response = "";
bool good = false;

It's always a good habit to initialise your variables.
Thanks everyone for your input. This helped me in the right direction
Topic archived. No new replies allowed.