You have inverted the sense of your test. Your for
loop can be written as this while
loop:
while (verifyPoll >> pollVote && verifyPoll.eof()) {
// ...
}
What you want is
while (!(verifyPoll >> pollVote && verifyPoll.eof())) {
}
Also, you must not declare a new verifyPoll
within the loop body, because now if the first answer does not validate, the loop will not terminate. You might instead assign a new string using
verifyPoll.str(pollVoteString);
but you should do it after the getline
.
2
solved Accepting only numbers in C++ program without the if else statement