@up - in this case it's not actually "dangling \n" problem, not just yet - anyway.
Input streams' operator>> overloaded for char* or std::string will return on any whitespace, so since "Joe Smith\n" has a space in it - operator>> will return "Joe" and " Smith\n" is left in the input buffer. That's why the latter attempts at extracting integer data from the stream would fail.
If you instead of operator>> use std::getline to get the full name - it will get everything till it finds \n, so a whole line, however, we know that at the point of calling it the input stream buffer is not actually empty because we called operator>> on it, to extract integers. When we extracted these integers - we left the dangling \n in there, and thus std::getline would return an empty string, that's why we need to extract/ignore the dangling newline.
So, while attempting to solve one problem we find ourselves knee deep in another.
Code:
// let input buffer be called "buf"
// buf == ""; -- it's empty, since we haven't done anything yet.
int a = 0;
std::cin >> a;
// what happens here? A couple of things:
// since buf is empty, we get prompted for data;
// we type in "42" and press Enter, since the prompt will wait for either EOF or newline
// now, buf == "42\n";
// since the operator>> overloaded on int was called, it will try and export a value out of buf that will look like an int and store it into a, while ignoring any whitespace before that data, and stopping on first character that doesn't fit as part of an integer
// "42" sure looks like int, but the next character - \n - sure doesn't look like a part of int representation, so "42" is extracted from buf, and the rest is left alone
// now, buf == "\n"; and value of 42 is stored into a
std::string s;
std::getline(std::cin, s);
// if buf is empty, we get prompted - but it isn't, as we now know
// so getline extracts everything till \n (or EOF) from buf (if there's no \n in buf, it will prompt for more data)
// then it stores everything it extracted into s; \n it merely "consumes" (extracts from buf, but doesn't store into the string). ;)
// so that leaves s as an empty string here, no prompt called.
We might want to put std::cin.ignore(std::numeric_limits<std::streamsiz e>::max(), '\n'); before we use getline() there.