Program using getline doesn't work after something is already input?

I made a program using getline that works fine. When I copied that program, word for word, semicolon for semicolon, it doesn't work anymore. I'm assuming that the reason is getline. In the program that I copied it into, you have to input a letter to get to the function that uses getline. Then, it displays everything, but completely skips over the inputting of the getline.
Last edited on
If you are using cin>> before getline(), the >> operator will leave newlines in the buffer, causing getline() to return the empty string immediately. Without any code I can't guess as to whether this is actually your problem or not.
1
2
3
4
5
6
7
8
cout << "Choose a function";
cin >> functionone;

if(functionone=="e" || functionone=="E")
	{
		cout << "...";
		getline(cin,inputnew);
        }


This is a basic summary of what happens before and during the getline function
Last edited on
I suspect the problem is exactly what I stated above. You should try to avoid mixing cin>> and getline(cin, ...) for exactly this reason, but you can also use cin's ignore() method to ignore the "extra" newline.
Thanks, it works now. From now on, I will use cin.ignore();
Topic archived. No new replies allowed.