Results 1 to 5 of 5

Thread: Getline Bug

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262

    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

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262
    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

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm a little late, but here's the official fix: http://support.microsoft.com/default...en-us%3B240015
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width