-
Getline Bug
guys,
i am having a problem with the following code
Code:
cout << "Please enter the cutomers address: ";
getline( cin, cust.address, '\n' );
getline( cin, cust.address, '\n' );
I have done all I need to do to fix the bug per msdn, I think, which is change the string header. In the above code, I have the getline code twice just to make the code work. Can anyone explain this. If I dont put it twice, the program just flies right by it.
I can also change the first getline to cin >> cust.address; and it will work also.
Thanks,
Jerel
-
I've seen a few ways to get past this...
Code:
cout << "Please enter the cutomers address: ";
cin >> ws;
getline(cin, cust.address, '\n' );
//or
cout << "Please enter the cutomers address: ";
cin.ignore();
getline(cin, cust.address, '\n' );
I think the first one (maybe even the second) require the <iomanip> header file.
-
the second one (with cin.ignore()) does not need any extra headers...
-
I had cin.ignore() in there before and it did not stop there either. I did not try something like cin.ignore(5) or something like that so if that would make a different, but I would think not.
My code works, but it is just kinda, well stupid what I have to do to fix it.
Jerel
-