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");
}
|
You created your ifstream object, but you never opened a file with it. After you have
add
Topic archived. No new replies allowed.