When you use
std::cin::operator>>, you leave the newline at the end of the buffer. That means that when you try to use
std::istream::getline, it stops immediately, as it immediately discovers the newline that you left in the buffer.
The easiest way to fix is to throw a
std::istream::ignore immediately beforehand:
1 2 3 4 5 6
|
std::istream& operator>>(std::istream& is, Team& t) {
char buf[100];
is.ignore();
is.getline(buf, 100);
// ...
}
| |
Of course, this will only work if the
only thing left in the buffer is the newline character; there are ways to ignore all characters up to the first newline, but there are hundreds of examples of that out there, and this is probably enough for your purposes.
Also, normally you put the
ignore directly after using
std::cin >>, because if the last stream operation happened to be another
getline you'll just end up ignoring the first character of your input. I didn't do it like that here for conciseness.