Friday, 16 January 2015

File Structures - Cpp program to create a new file and write some data into it.


This is a C Program which creates a new file and writes some data into it.

We will use a filestream classes to create a new file in write mode then we enter some data into it.

Then we read  that data until end of file is reached and place that data in the  file we just created.

PROGRAM :
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    char data[100];
    ofstream outfile;
    outfile.open("sample.txt");
    cout << "Write some text here !\n";
    cin.getline(data,100);
    outfile << data << endl;
    outfile.close();
    return 0;
}

OUTPUT : 






No comments:

Post a Comment