File Program 4


Write a program to read product name and product price from keyboard and write it in “product.txt” file and read from file in text mode.



#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void main()
{
            int pprice,pprice1;
            char name[10],name1[10];
            clrscr(); 
            cout<<"\n Enter product price and name";
            cin>>pprice>>name;
            ofstream of1("product.txt");
            of1<<pprice<<endl;
            of1<<name<<endl;
            of1.close();
            cout<<"\n Read data from file\n";
            ifstream if1("product.txt");
            if1>>pprice1;
            if1>>name1;

            cout<<pprice1<<" "<<name1;
            if1.close();
             getch()
}