Skip to content

Github Support Community for C++ Developers #21450

Answered by fire-eggs
bhawesh2002 asked this question in General
Discussion options

You must be logged in to vote

cin and getline don’t play nice together. cin leaves a newline in the input buffer, which causes your getline to fail.

You could just use cin instead of getline to populate name or you could call cin.ignore() just before calling getline.

See here.

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants