Bootstrap

用read()和write()读写二进制文件

#include<iostream>
#include<fstreeam>
#include<cstring>
#include<cstdlib>
using namespace std;
class merchandise
{char name[20];
 doube price;
 public:
	merchandise(char*tn="",double up=0)
	{strcpy(name,tn);
	 price=up;
	}
 	friend istream &operator>>(istream &stream,merchandise& m);
	friend ostream &operator<<(ostream &stream,const merchandise& m);
};
istream &operator>>(istream &stream,merchandise& m)
{cout<<"输入名称和单价"<<endl;
 stream>>m.name>>m.price;
 return stream;
}
ostream &operator<<(ostream &stream,const merchandise& m)
{stream<<"商品名称:"<<m.name<<" "<<"单价:$"<<m.price<<endl;
 return stream;
}
int main()
{merchandise m1,m2;
 cin>>m1>>m2;
 ofstream outfile("a.txt",ios::out||ios::binary);
 if(!outfile)
	{...}
 else
	{outf
;