Newline strangely persists

Hi everyone,

I wrote a small menu which is accessed from a string a user is prompted to type. After the string is sent with the return/newline key, I have a function prompting the user for a line. The problem is that when the getline is reached it immediately skips as if I entered "return" twice. Here is how it looks approximately:

1
2
3
4
5
6
7
8
9
10
  string command;
  cin>>command;

 if (command=="option1")
     {
       myfunction(MyClass mc);
      
       //etc...  
      }


And so it enters the function that looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

function (MyClass & mc)

{string first_thing;
 string second_thing;
 sting third_thing;
 
 cout<<"Please enter first thing: ";

getline (cin, first_thing);

cout<<"Please enter second_thing: ";

getline (cin, second_thing);

//etc...
}


So when if type in "option1" and send it, it prompts:

Please enter first thing: Please enter second thing:

As if the first part was skipped when I typed in my first command.

Any ideas what is going on?
What you type goes into a buffer.

Your program removes some things from that buffer.

Sometimes, depending on how you coded it, you leave the newline inside the buffer.

http://stackoverflow.com/questions/10553597/cin-and-getline-skipping-input
Topic archived. No new replies allowed.