I'm reading lines from std::cin
with a while
loop that ends when EOF
is introduced. After exiting the loop, I call std::cin.clear()
to put the stream back to normal and read again, but it's not entering the second loop.
I've checked the eofbit
and it's set to false
. The failbit
is set to false
as well and the goodbit
is set to true
. The gcout
after clearing is 0
. Here's the code I'm running:
while (getline(std::cin, person)) {
// Do stuff until I enter ^D
}
std::cin.clear();
// Adding std::cin >> person here doesn't work either
while (getline(std::cin, person)) {
// It never enters this loop
}
What am I doing wrong?