I am writing a program to take input from a file and display it on the console. The problem is that the last entry is being repeated twice. The code is as follows:-
int main(void)
{
    string filename;
    int grades;
    cout<<"Enter the filename:"<     getline(cin,filename);
    ifstream inFile(filename.c_str(),ios::in);
    if(!inFile){
        cout<<"File does not exist."<         exit(1);
    }
    while(!inFile.eof())
    {
        inFile>>grades;
        cout<     }
    inFile.close();
    return 0;
}
Can you please help me in finding out the mistake? I have searched on the web and my code seems to be syntactically and logically correct.
No comments:
Post a Comment