*** Quoting Rick Svyzek from a message to All ***
RS>
RS> Hi, I got a problem I been working on. I'm a beginner at C++
RS> programming. What I need help with is how to read a text file line
RS> line with a program. I can get my program to open a file stream and
RS> it reads the first line then exits. Could someone please point me
RS> the right direction :)
#include // you should have this already
char Line[81]; // thats 0-79 chars (80), and 1 null at the end (1), 81!
ofstream funFile;
void main()
{
funFile.open("filename.ext"); // you should have this
funFile.getline(Line,80,'\n') // get line, cutting off at 80 chars or when a
// new line is incountered (\n) (system
dependent
// always use \n for your CRLF or whatever.
cout << Line << endl; // if I remember right, it doesn't put a \n
// on the end of the line in getline, you must
// use endl to and an end of line, could also
// have used '\n'
funFile.close();
} // end of main
Happy birthday
Wayne
=[Visit the RazSoft homepage!]=[http://www.sound.net/~fileland]=
--- FMail/386 1.22
---------------
* Origin: =(Mental Floss)=(913-383-2925)= (1:280/191)
|