Why the program can not read the file?

#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;
int main(){

ofstream fout("C:\\Users\\leand\\Desktop\\alunos.txt");

const int MAX=10;
int cont=1;
char num, le[MAX];

cout<< "Digite 20 numeros: \n";

while(1){
cout<<"Digite o "<<cont<<" numero: \n";
cin>>num;
fout<<num<<"\n";
if(cont==5) break;
cont++;
}

ifstream fin("C:\\Users\\leand\\Desktop\\alunos.txt");
while(!fin.eof()){
fin.getline(le,MAX);
cout << le << endl;
}
system("pause");
}
You should probably close the ofstream() before you try to open the ifstream().

Topic archived. No new replies allowed.