I am currently trying to read input from a text file with only one line in C++; I am able to extract the one line of text from the file successfully to a string using the std::getline(file, string). After extracting the line there is no more text. When I try to check the state of the stream, it will never return false when file.good() is called, and the known "end" of the file is reached. Why is this? See code below:
#include<fstream>
#include<cstring>
using namespace std;
ifstream file;
string test;
file.open("HW6.txt");//HW6.text is one line text file
getline(file,test);//extracts the line of text; file should be blank now
cout<<file.good(); //this returns true
getline(file,test); //attempt to extract text from blank file
cout<<file.good(); //this returns true still