Tuesday, 24 February 2015

File Read and Write in C++

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
main()
{
clrscr();
ofstream out("Items.txt",ios::out);

out<<"\nShirts"<<" "<<350<<endl;
out<<"\nTrousers"<<" "<<450<<endl;
out<<"\nJeans"<<" "<<750<<endl;
out.close();

ifstream in("Items.txt",ios::in);
char item[50];
float cost;
in>>item>>cost;
cout<<"\n Item is "<<item;
cout<<"\n Cost is "<<cost;
in>>item>>cost;
cout<<"\n Item is "<<item;
cout<<"\n Cost is "<<cost;
in>>item>>cost;
cout<<"\n Item is "<<item;
cout<<"\n Cost is "<<cost;

in.close();
getch();
}

No comments:

Post a Comment