Just use getline() when you read strings from the user. Remove cin>>newptr->title and cin>>newptr->author from your code.
mikrosfoititis
Junior Poster in Training
74 posts since Nov 2011
Reputation Points: 18
Solved Threads: 11
Beware of mixing calls to >> and getline() in the same program. The default termination character for getline() is the newline char. getline() will stop putting additional information into the target string whenever if finds the terminating char. getline() will remove the terminating char from the input stream. White space characters (newline, tab, etc) are the terminating characters for >>. >> does not remove the terminating char from input stream. >> and getline() fequently use the same input stream, for example, both use cin in your program.
In your program >> is called before getline() is called and is terminated by newline. getline() is using the default newline char as the terminating char. Therefore, the first thing getline sees is the newline char left in the input stream by the preceding call to >> and it doesn't put the expected information into the expected variarble. It doesn't matter whether >> is called immediately before getline() or not in the programming code.
Options to deal with this are:
1) Don't mix >> and getline() in the same program.
2) Attempt to clear the input stream before every call to getline() if you do mix >> and getline().
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396