Sign in with
Sign up | Sign in
Your question

Pls help with this C++ program

Tags:
  • Programming
  • Apps
Last response: in Apps General Discussion
Share
August 21, 2009 10:47:09 AM

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.

More about : pls program

August 21, 2009 2:33:46 PM

well, do you have a textbook?
Related resources
August 21, 2009 4:32:43 PM

mindless728 said:
well, do you have a textbook?



I tried reading it.But no sucess.
August 21, 2009 4:47:42 PM

what you will need

include directive:
  1. #include <fstream>


some lines for using fstream (i am assuming you know how to output to screen):
  1. ifstream inFile;
  2. ...
  3. inFile.open("TEST.TXT"); //doesn't need to be all caps for windows
  4. ...
  5. inFile.getline(); //look up this function yourself
August 21, 2009 4:54:50 PM

also when done with a file
  1. inFile.close();


test if a file is not open
  1. if(!inFile.is_open()) {
  2. ...do stuff...;
  3. }


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++)
August 21, 2009 5:30:49 PM

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?


August 21, 2009 6:45:29 PM

well you should be able to, just open the txt as a binary file (thats what dat gets opened as) and it should work
August 22, 2009 3:01:06 PM

Well Thanx Mindless for all ur help. I will Use that link of MSDN.

!