|
-
Jan 13th, 2003, 10:07 PM
#1
Thread Starter
Hyperactive Member
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
-
Jan 13th, 2003, 10:24 PM
#2
Stuck in the 80s
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.
-
Jan 14th, 2003, 07:07 AM
#3
Fanatic Member
the second one (with cin.ignore()) does not need any extra headers...
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Jan 14th, 2003, 09:08 AM
#4
Thread Starter
Hyperactive Member
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
-
Apr 8th, 2003, 09:12 PM
#5
Stuck in the 80s
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|