HOME

Sunday, November 29, 2015

PROGRAM FOR PUT AND GET FUNCTION IN FILE HANDLING

#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
    char str[50];
    cout<<"Enter the string"<<endl;
    cin>>str;
    fstream obj;
    obj.open("abc.txt",ios::in|ios::out);
    int length;
    length=strlen(str);
    for(int i=0;i<length;i++)
    {
        obj.put(str[i]);
    }
    obj.seekg(0,ios::beg);
    cout<<"READING FROM FILE"<<endl;
    char ch;
    while(obj)
    {
        obj.get(ch);
        cout<<ch;
    }
    obj.close();
    return 0;
}

No comments:

Post a Comment