I am getting caught in an infinite loop, weirdly, while trying to take in my input. I've been able to use a loop like this in the past appropriately, but for some reason I'm getting caught here:
vector<string> boolean_forms;
while (!cin.eof()) {
cout << "HELP IM STUCK";
string line;
getline(cin,line);
if (!cin.fail()) {
boolean_forms.push_back(line);
}
}
I don't know, is there a better way to do this? I can't for the life of me figure out why this is causing issues. Is it possible that there's code elsewhere in my program that's messing things up? I can't imagine what it would be, as this is just reading from a file which I don't write to at all.
Update: After changing to doing input directly instead of first checking end of file first, I get a segmentation fault. The segfault isn't caused by anything outside this loop, as if I try pushing back the line directly instead of from the input, the program runs as it should and I get expected output.
This is... frustrating. I'm getting downvoted to hell while I've tried all of the solutions proposed and none of them have worked. If I read in before checking end-of-file, I get a segmentation fault. If I check eof first and then getline, I get an infinite loop. If I hard-code insert the line I'm trying to check into the vector, my code runs fine so I know it must have to do with reading from cin. I read in with ./a.out < input.txt which has worked for me numerous times until now.