C++ Program to Read and Write a Text File

int main()
ofstream outf("ITEM");
cout<<"Enter item name:"; char name[30]; cin>>name;
outf<<name<<"\n"; // write to file ITEM
cout<<"Enter item cost:"; float cost; cin>>cost;
outf<<cost<<"\n"; outf.close(); ifstream inf("Item"); inf>>name; // read name from file ITEM
inf>>cost; // read cost from file ITEM
cout<<"Item name:"<<name<<"\n";
cout<<"Item cost:"<<cost<<"\n";
return 0;