file reading - ... - help!
I am doing windows programming, but I still mess around with console programs. I ALSO USE Dev-C++ 4.01! Anyhow, I am messing around with fstream. I can use ofstream to write 9 random numbers to a file on new lines, but I can't read it. Here's the code:
#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
#include <conio.c>
#include <time.h>
int main() {
int rnd = 0 ;
int nLine ;
char numx ;
cout << "Press any key..." ;
getch() ;
cout << "\n\n" ;
for(int x=0 ; x < 9 ; x++)
{
rnd=rand() % 9 ;
cout << "\nInputting " << rnd ;
ofstream numbers ("numList.lst", ios::app) ;
if( numbers.is_open() )
{
numbers << rnd << "\n" ;
numbers.close() ;
}
}
cout << "\n\n";
ifstream fin ("numList.lst");
while(! fin.eof() )
{
fin.getline(nLine, 10) ;
cout << numx ;
}
getch() ;
return 0 ;
}
When I try and use ifstream(fin) to read it, it outputs a bunch of numbers. How do I read it line-by-line and every time the file is a new line, put the new number on another line? ANY HELP IS APPRECIATED!