Programming

C++ Program to Write and Read of User Input File

C++ Program to Write and Reading of User Input File

Source Code

#include<iostream>
#include<fstream>
#include<conio.h>
using namespace std;
int main()
{
    char buffer[100],name[10], address[10];
    int maxlength=100;
    ofstream outf(“test.txt”);
    {
        cout<<“\nEnter the name : “;
        cin>>name;
        outf<<name<<endl;
        cout<<“\nEnter the address : “;
        cin>>address;
        outf<<address<<endl;
    }
        outf.close();
        ifstream fin(“test.txt”);
    {
        fin>>name>>address;
        cout<<“\nThe name is : “<<name<<endl;
        cout<<“\nThe address is : “<<address<<endl;
    }
        fin.close();
        getch();

}

Output

reading and writing files

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.