Tom's Hardware > Forum > Applications > Programming > Pls help with this C++ program

Pls help with this C++ program

Forum Applications : Programming - Pls help with this C++ program

Tom's Hardware: Over 1.4 million members in 6 different countries available to answer all your high-tech questions. Sign up now! Its free!
Word :    Username :           
 

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.

Sponsored Links
Register or log in to remove.

try looking through this
http://cplusplus.com/doc/tutorial/

it some some good stuff you may be able to use

Reply to mindless728

mindless728 wrote :

well, do you have a textbook?




I tried reading it.But no sucess.

Reply to shubham1401

what you will need

include directive:

Code :
  1. #include <fstream>



some lines for using fstream (i am assuming you know how to output to screen):

Code :
  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

Reply to mindless728

the msdn library is very expansive, try it sometimes, its how i learned sockets, multi threaded, and winapi programming

for fstream:
http://msdn.microsoft.com/en-us/li [...] S.60).aspx

Reply to mindless728

also when done with a file

Code :
  1. inFile.close();



test if a file is not open

Code :
  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++)


Message edited by mindless728 on 08-21-2009 at 06:58:13 PM
Reply to mindless728

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?


Reply to shubham1401

well you should be able to, just open the txt as a binary file (thats what dat gets opened as) and it should work

Reply to mindless728

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

Reply to shubham1401
Tom's Hardware > Forum > Applications > Programming > Pls help with this C++ program
Go to:

There are 820 identified and unidentified users. To see the list of identified users, Click here.

Sponsored links
  • Ask the community now
  • Publish
Ad
They won a badge
Join us in greeting them