Jun 9, 2009 at 4:29am UTC
I'm not sure what is wrong with my getline(). The program doesn't cin for address or notes. any input would be helpful, Thanx
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct Contact
{
string firstName;
string lastName;
string cellPhone;
string housePhone;
string otherPhone;
string address;
string emailAddress;
string notes;
};
void DisplayContact(Contact contact);
Contact AddContact();
int main()
{
DisplayContact(AddContact());
}
Contact AddContact()
{
string address;
string note;
string buffer;
Contact tempContact;
cout << setw(25) << "--New Contact--\n\n";
cout << "First Name - ";
cin >> tempContact.firstName;
cout << "Last Name - ";
cin >> tempContact.lastName;
cout << "Cell Phone - ";
cin >> tempContact.cellPhone;
cout << "House Phone - ";
cin >> tempContact.housePhone;
cout << "Other Phone - ";
cin >> tempContact.otherPhone;
cout << "Address - ";
getline (cin, tempContact.address);
cout << "E-mail - ";
cin >> tempContact.emailAddress;
cout << "Notes - ";
getline (cin, tempContact.notes);
return (tempContact);
}
void DisplayContact(Contact contact)
{
cout << contact.lastName << ", " << contact.firstName << endl;
cout << "Cell Phone - " << contact.cellPhone << endl;
cout << "House Phone - " << contact.housePhone << endl;
cout << "Other Phone - " << contact.otherPhone << endl;
cout << "Address - " << contact.address << endl;
cout << "E-mail - " << contact.emailAddress << endl;
cout << "Notes - " << contact.notes << endl;
}
Last edited on Jun 9, 2009 at 4:32am UTC
Jun 9, 2009 at 4:34am UTC
It probably has to do with your mixing of cin>> and getline(). When you use cin>>, it probably leaves a '\n' in the buffer so the next getline() returns immediately because it hits that newline.
Jun 9, 2009 at 4:36am UTC
oic... is there anyway to fix this?
Jun 9, 2009 at 6:58am UTC
Last edited on Jun 9, 2009 at 7:04am UTC