HOME

Sunday, November 29, 2015

WRITING AND READING FROM FILE USING CONSTRUCTOR FUNCTION

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    char name[20];
    int age;
    cout<<"ENTER NAME AND AGE"<<endl;
    cin>>name>>age;
    ofstream obj("1.txt");
    obj<<name<<"\n";
    obj<<age<<"\n";
    obj.close();
    ifstream obj1("1.txt");
    char str[20];
    int x;
    obj1>>str;
    obj1>>x;
    obj1.close();
    cout<<"NAME= "<<str<<endl;
    cout<<"AGE= "<<x<<endl;
    return 0;
}

No comments:

Post a Comment