28 Nov 2019

  • November 28, 2019
  • Amitraj
// Cpp program to create a file and store data into it and get back file data.

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char name[30];
float cost;
ofstream outf("abc.txt");
cout<<"Enter item name:";
cin>>name;
outf<<name<<"\n";
cout<<"Enter item cost:";
cin>>cost;
outf<<cost<<"\n";
outf.close();
 
ifstream inf("abc.txt");
inf>>name;
inf>>cost;
cout<<"\n item name:"<<name;
cout<<"\n item cost:"<<cost;
inf.close();
return 0;
}

OUTPUT:












Translate

Popular Posts