Getline help

I am trying to use the getline function inside of a function.

I am calling the setMakeModel function in my constructor.

1
2
3
4
5
6
void setMakeModel () 
	{
		cout << "What is the make and model of your vehical : "<<endl;
		getline( cin, makeModel );
		
	};


Every time I run the code it never allows me to enter anything all it does is skip over it. I am trying to set the variable makeModel with the input from the question.
You need to remove the garbage in the buffer before trying to use getline. You want this: http://www.cplusplus.com/reference/iostream/istream/ignore/
Thank you for the help it worked great.

1
2
3
4
5
6
7
void setMakeModel () 
	{
		cin.ignore();
		cout << "What is the make and model of your vehical : "<<endl;
		getline( cin, makeModel );
		
	};



I put the cin.ignore() and it works great.
Topic archived. No new replies allowed.