Problem With Cin Getline For Spaces
Hey! I have this problem. It goes directly to the Last Name, it skips the first name. What do I do?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
int num;
char firstname[60];
char lastname[60];
int contact;
cout<<setw(40)<<"\n\nPASSENGER INFORMATION";
cout<<"\n\n\nEnter FIRST NAME: ";
cin.getline(firstname,60);
cout<<"\nEnter LAST NAME: ";
cin.getline(lastname,60);
cout<<endl;
cout<<"Enter CONTACT NUMBER: ";
cin>>contact;
cout<<endl<<endl;
system("CLS");
|
You probably have a newline left hanging around in the stream from a previous formatted extraction (via
>>).
1 2 3
|
cout << "\n\n\nEnter FIRST NAME: " ;
cin >> ws ; // remove leading whitespace
cin.getline(firstname, 60) ;
|
Topic archived. No new replies allowed.