int main(int argc, char** argv)
{
ifstream input;
ofstream output;
input.open("input.txt");
output.open("output.txt");
char c;
output << "ID\tLName\tFName\tQ1 Q2 Q3 Q4 Q5 Q6 T1 T2 Final" << endl;
output << "------------------------------------------------------" << endl;
//Loop through each line until there is none left.
string s;
while (getline(input, s))
{
output << readNext(input) << "\t"; //ID
output << readNext(input) << "\t"; //FName
output << readNext(input) << "\t"; //LName
output << endl;
}
return 0;
}
string readNext(ifstream& input)
{
string s;
char c;
if (input.peek() == ',') input.get(c);
do {
input.get(c);
s += c;
} while(input.peek() != ',');
return s;
}
The line "while (getline(input, s))" gets me stuck in an infinite loop. Could anyone explain why? I've been told by numerous people that this is the correct way to read input rather than looking for an EOF.
Sample Input
11111,Lu,Youmin,10,9,8,10,8,9,95,99,100
22222,Lu,Eddie,7,8,9,10,10,10,100,92,94