help please

i'm trying to read my complete file using eof() but i cant. can anyone tell me where am i making mistake ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
    ofstream myfile;
    myfile.open("file.txt", ios::app);
    int cgpa;
    string name;
    cout<<"Enter name: ";
    cin>>name;
    cout<<"Enter CGPA: ";
    cin>>cgpa;
    myfile<<name<<endl;
    myfile<<cgpa<<endl;
    myfile.close();
    ifstream infile;
    while(!infile.eof())
    {
                        cout<<"\n";
                        infile >> name;
                        infile >> cgpa;       
    }
    infile.close();
    system("PAUSE");
}
closed account (2UD8vCM9)
You created your ifstream object, but you never opened a file with it. After you have
 
ifstream infile;


add

 
infile.open("file.txt); 
> ifstream infile;
¿which file are you trying to read?

> using eof()
don't.
http://www.parashift.com/c++-faq/istream-and-eof.html

> but i cant
¿how do you know that?
Topic archived. No new replies allowed.