Write a program to open a file in C++ “test.txt” and write “c++ programming….” “

Home Forums C++ Write a program to open a file in C++ “test.txt” and write “c++ programming….” “

This topic contains 0 replies, has 1 voice, and was last updated by  admin 7 months, 4 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #5244

    admin
    Keymaster

    /*
    Write a program to open a file in C++ “test.txt” and write
    “c++ programming….”
    “test program….”
    into the file. Read the file and display the contents.
    */

    #include<iostream.h>
    #include<fstream.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    ofstream fout;
    fout.open(“test.txt”);
    fout<<“c++ programming….\n”;
    fout<<“test program….\n”;
    fout.close();
    const int N=100;
    char line[N];
    ifstream fin;
    fin.open(“test.txt”);
    cout<<“Contents of the file:\n\n”;
    while(fin)
    {
    fin.getline(line,N);
    cout<<line<<endl;
    }
    fin.close();
    getch();
    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.