trap for beginners in C++
Denys Shabelnyk

Denys Shabelnyk @snorri1986

About: Software engineer

Location:
Copenhagen, Denmark
Joined:
May 8, 2020

trap for beginners in C++

Publish Date: Jul 24
0 0

Following one of C++ course I found one interesting example how to correctly use combination std::cin together with std::getline().
Look at firts example below:

What do you think the output will be ?
Your age is
Your name is
but not. Output is below:

To avoid this strange behaviour always use std::cin.get() before std::cin and std::getline() like on the code snippet below:

Now you will get correct output.

Be careful and happy coding!

Comments 0 total

    Add comment