0

I am working on a basic linked list program and i seem to be having problems with the getline() function.

I try to input data in to my struct:

cout<<"\n\nPlease enter the name of the student: ";
    getline(cin, temp->name);
    cout<<"Please enter "<<temp->name<<"'s class: ";
    cin>>temp->grade
    cout<<"Please enter "<<temp->name<<"'s GPA: ";
    cin>>temp->gpa;

but when i do this it ignores the first getline statement and continues to the next ourputr line and then i can enter the students class. My question is why does it jump over the getline?

If you need more of the code i can post it all. Its only about 100 lines so far.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by shindu
0

This is very often an issue where you have an excess newline character in the input stream from an earlier cin statement. The cin statemnent doesn't consume that newline. getline sees the newline, takes it, and doesn't pause for input. You want to flush the input stream so that any excess characters are removed before the getline statement. That way the program will pause when it sees getline.

http://www.daniweb.com/forums/thread90228.html

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.