cin.getline() does not work if placed after another cin.

Hello,

I nee to get a string line from console. I am using cin.getline(), but this function does not work if I have a cin placed first.

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void person::person_info()
{	
	string name;
	string last_name;
	char address[256];

	//cin.getline(address,256); //<-----works here!
	cout<<"Enter First Name: ";cin>>name;
	cout<<"Enter Last Name: ";cin>>last_name;
	cout<<"Enter Address: ";cin.getline(address,256);//<-----does not work here
	cout<<address;

	
}


I will apreciate any help.

Thank you.

Angel
I got it to work!!

I place:

cin.ignore();

just before
cin.getline(address,256);

For what I read, it flushes cin; I am not sure exactly how it does it, but now it works.

http://www.cplusplus.com/forum/beginner/9148/ << read that you'll find it useful! :)
Topic archived. No new replies allowed.