void NewCustInfo(CustData &cust)
{
	cout << "Customer Name: ";
	getline(cin, cust.name);

}

CustData is a structure that is declared, and the name data member of that struct is of type string. For some reason when I call this function(there are no compile errors), it displays the cout statement, but then completely skips over the getline function. Any ideas?

Thanks

Recommended Answers

All 3 Replies

Does it occur after some other input? If so, there may be still be some lagging information in the input stream that it's grabbing.

Try placing cin.ignore(); directly before it.

void NewCustInfo(CustData &cust)
{
	cout << "Customer Name: ";
	getline(cin, cust.name);

}

CustData is a structure that is declared, and the name data member of that struct is of type string. For some reason when I call this function(there are no compile errors), it displays the cout statement, but then completely skips over the getline function. Any ideas?

Thanks

Its probably most likely that there is a new line character in the stream. This happens when you read in a number. As suggested,
place cin.ignore() as the first statement in the function. Then go
on normally.

Thanks guys, that fixed my problem. I shoulda been able to figure that out on my own =(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.