Thread: getline help!

  1. #1
    Registered User
    Join Date
    Mar 2002

    getline help!

    I have this function for my address book program but the first getline isn't working, somebody please tell me why!

    PHP Code:
    void ChangeEntry (sturec &bookfstream myfileint &recordnum)

    int whichnum;
    char temp1[50], temp2[50];
    cout << "\nRecord number to change? ";
    cin >> whichnum;

        if (
    whichnum recordnum)
    cout << "\nI'm sorry, there are not that many records.  \nPlease select a record"<<
    " between 0 and "<<recordnum<<endl<<endl;

    cout <<"Last name: "<<temp1;
    cout <<"\nLast name? \n";
    cin.getline (temp215);
    cout << temp2;
            if (
    strcpy (book.lastnametemp2);
    cout <<"First name: "<<temp1<<endl;
    cout <<"First name? ";
    cin.getline (temp215);
            if (
    strcpy (book.firstnametemp2);    


  2. #2
    Registered User
    Join Date
    Mar 2002
    because there is still a newline char in the input buffer following the line:

    cin >> whichnum;

    to fix it add this after the above line:


    As you get more sophisticated with your programming skills read about istream methods (>> and getline in particular) in your favorite textbook (as there are some picky ooni details that can trip you up if you don't know how these methods work), or do a search on this board using getline as the searchword.

  3. #3
    Registered User
    Join Date
    Mar 2002

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  2. getline problem
    By Bitphire in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2004, 04:42 PM
  3. getline help
    By ProjectsProject in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2004, 11:12 AM
  4. getline not working right
    By talz13 in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2003, 11:46 PM
  5. getline with string class in Borland C++
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-08-2003, 02:59 PM