Thread: getlines..

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    42

    getlines..

    hey whats up..i hate getlines..we're working in UNIX on a binary file program..

    and i need to ask for a persons name...and i tried to ways..

    way 1)
    Code:
    string key;
    cout << "Enter name\n"; //input: Michael Jordan
    getline(cin, key, '\n');
    cout << key << endl; //output: it skips over this, doesn't halt at the getline to get the value...rather just moves right along w/ the function and the key being some crazy value
    way 2)

    i just inserted a cin.ignore to see what would happen..and it halts, but still pulls out a " " instead of "Michael Jordan", does anyone know what i'm doing wrong?

    Thanks!

    BBNERD!
    Last edited by BODYBUILDNERD; 03-25-2003 at 11:34 AM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    sorry guys the \n isn't in my real code, but i still have the problem!

    BBNERD

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Try the getline fix, because that works for me:

    Fix to <string>
    The header <string> contains a definition for template function getline. It has a lookahead problem -- typing a delimiter to end the input doesn't return control until you type yet another character. Change the code as indicated by the comment:

    else if (_Tr::eq(_C, _D))
    {_Chg = true;
    _I.rdbuf()->snextc(); // replace snextc with sbumpc
    break; }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Valgrind says I suck at memory management :)
    By carrotcake1029 in forum C Programming
    Replies: 6
    Last Post: 02-01-2009, 08:10 PM