Wednesday, 27 June 2012

c++ program that write into a file and read from file using function.

#include<iostream>
#include<fstream>
using namespace std;

    void inputfile(char b)
        {
        ofstream myfile(b);
        char c[100];
        int a;
        cout<<"enter your number :";
        cin>>a;
        cout<<endl<<"enter your First Name:";
     


cin.getline(c,100);
        myfile<<a<<endl<<c;
        myfile.close();
        }
   
    void outputfile(char b)
        {
        ifstream myfile(b);
        char c[100];
        int a;
        myfile>>a>>c;
        cout<<endl<<"your number is:"<<a<<endl;
        cout<<"your First Name:"<<c;
        myfile.close();
        }

    int main()
    {
    char c[100];
    cout<<"Enter file Name:";
    cin.getline(c,100);
    inputfile((char *) &c);
    outputfile((char *) &c);
    return 0;
    }

No comments:

Post a Comment