Proxy > Gmail Facebook Yahoo!

C++ program to open a file



This program will show you how to open a file in C++.We’ll need to include the fstream header file. The fstream header file contains the necessary classes to read, write files. It includes
ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and write from/to files.

#include <iostream>
#include <fstream>
using namespace std;
int main()
 
{
 
 ofstream obj;  //Creating an object for class ofstream 
 obj.open("filename.txt"); //Opening the file "filename.txt"
 obj << "Hello";  //Writing to filename.txt
 obj.close(); //Closing file
 cin.get();
 return 0;
}


Responses

0 Respones to "C++ program to open a file"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar