Program to WORKING WITH MULTIPLE FILES

Home Forums C++ Program to WORKING WITH MULTIPLE FILES

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

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

    admin
    Keymaster

    //WORKING WITH MULTIPLE FILES
    //Creating files with open() function
    #include <iostream.h>
    #include<fstream.h>
    int main()
    {
    ofstream fout;
    fout.open(“country”);
    fout<<“United states of America \n”;
    fout<<“United Kingdom”;
    fout<<“South korea”;
    fout.close();
    fout.open(“capital”);
    fout<<“Washington\n”;
    fout<<“London\n;
    fout<<“Seoul \n”;
    fout.close();
    const int N =80;
    char line[N];
    ifstream fin;
    fin.open(“country”);
    cout<<“contents of country file \n”;
    while (fin)
    {
    fin.getline(line,N);
    cout<<line;
    }
    fin.close();
    fin.open(“capital”);
    cout<<“contents of capital file”;
    while(fin)
    {
    fin.getline(line,N);
    cout<<line;
    }
    fin.close();
    return 0;
    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.