OK, so I am redirecting the input from a file. The input is read into a string. The problem is, when the input file ends, the program still reads empty lines and goes into an endless loop. I have added an if statement for it to detect 5 empty entries and exit the loop. Anyway to just make the program understand that the input, if from a file, is an EOF?
#include <string>
using namespace std;
int main()
{
string command = "";
int blanks = 0;
do{
cout << endl;
cout << "> ";
command.clear();
std::getline(cin, command, '\n');
//some code
if ( command.length() <= 0 ){
blanks++;
if(blanks > 5){
cout << "No command was entered for 5 times. " << endl;
cout << "Quiting..." << endl;
break;
}
}while(condition == true);