Pls help with this C++ program

shubham1401

Distinguished
Apr 21, 2009
51
0
18,580
My teacher gave my class an Assignment which i have to submitt on monday.
Here is one of the questions.
Based on Data File Handling and txt files.

Q.Write a c++ program, which reads one line at a time from the disk file
TEST.TXT and display it to a monitor. Your program has to read all the contents of the file. Assume the length of the line not to exceed 80 characters .You have to include all the header files if required.

I have no idea how to do it as i was not well and missed some classes.
Pls make it for me.I will do the rest of programs myself.
 

mindless728

Distinguished
Jul 15, 2008
130
0
18,660
what you will need

include directive:
Code:
#include <fstream>

some lines for using fstream (i am assuming you know how to output to screen):
Code:
ifstream inFile;
...
inFile.open("TEST.TXT"); //doesn't need to be all caps for windows
...
inFile.getline(); //look up this function yourself
 

mindless728

Distinguished
Jul 15, 2008
130
0
18,660
also when done with a file
Code:
inFile.close();

test if a file is not open
Code:
if(!inFile.is_open()) {
     ...do stuff...;
}

been a long time since i have used fstream, i use file handles (FILE*) for all my file needs (though it really is c not c++)
 

shubham1401

Distinguished
Apr 21, 2009
51
0
18,580
Thank you mindless.You are really the one with Mind!!!he he he

Just one more question. I am familiar with working with dat files.
dat files use read() and write() function.

can they also be used with txt files?