Apr 2, 2016 at 1:06am
#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");
}
Apr 2, 2016 at 1:29am
You should probably close the ofstream() before you try to open the ifstream().