Because when you say getline , you say you want to get a string ... A string that ends with \n , the ending is an integral part of it.
When you say cin >> something , you want to get exactly something , nothing more. The final marker is not part of it, so it is not consumed. Unless you have a special type for the string, but there is no such thing in the standard library.
Despite the lack of references from the standard, this may be perceived as an opinion, but it is logical. They have different semantics . There is another difference. getline works as unformatted input , operator>> works as formatted input . I highly recommend reading these links to get the differences. This also suggests that they are semantically different.
Another answer, better or less debatable, would be to quote a standard that, I am sure, says how getline behaves, and how operator>> behaves for different types and says that it works like that because the standard says so. That would be good, because the standard absolutely defines how everything works, and it can do it arbitrarily ... And this rarely explains the motivation and logic of the design.
luk32 source share