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.

Recommended Answers

All 2 Replies

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

That works just fine thanks mate!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.