Output file stream is used to send or write data to a

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: d to send or write data to a file. For each file that your program uses, a distinct file stream object must be created. Declaration of input and output file stream ifstream in_stream; ofstream out_stream; Ifstream and ofstream are classes. in_stream and out_stream are objects of class ifstream and ofstream. File stream methods or functions Each file stream object has access to prewritten functions defined for its respective ifstream or ofstream class. Functions like opening a file, closing a file, reading data from a file, writing data from a file etc... #include<fstream.h> #include<stdlib.h> // needed for exit() int main() { in_file.open("test.dat"); if(in_file.fail())//check for a successful open { cout<<"file not opened"<<endl; exit(1); } cout<<The file has been successfully opened<<endl; return 0; } Example 1...
View Full Document

This document was uploaded on 07/06/2011.

Ask a homework question - tutors are online