64,637
社区成员
发帖
与我相关
我的任务
分享
#include<fstream>
using namespace std;
int main()
{
ofstream outfile("abc.txt");
outfile<<"fdtgerqyeophy"<<endl;
outfile.close();
return 0;
}
include<iostream>
#include<fstream>
usingnamespacestd;
intmain()
{
string a="SDFGASSADFSGSDG" ;
ofstream outfile("abc.txt");
outfile<<a<<endl;
outfile.close();
return0;
}
方法2
class Hotel
{
private:
int No;
string name;
string cty;
int total_room;
int proom;
int proom_empty;
double proom_money;
int hroom;
int hroom_empty;
double hroom_money;
public:
// 运算符重载决定了写到文件的文本格式
friend ostream&
operator << (ostream &out,Hotel &hot)
{
out <<hot.No<<" "<<hot.name<<" "<<hot.cty<<" "<<hot.total_room<<" "<<hot.proom
<<" "<<hot.proom_empty<<" "<<hot.proom_money<<" "<<hot.hroom
<<" "<<hot.hroom_empty<<" "<<hot.hroom_money<<endl;
return out;
}
friend istream&
operator >> (istream &in,Hotel &hot)
{
in >> hot.No >> hot.name >> hot.cty >> hot.total_room >>hot.proom
>> hot.proom_empty >> hot.proom_money >>hot.hroom
>> hot.hroom_empty >> hot.hroom_money;
return in;
}
};
int loadfile(list<Hotel> &list_hot) //读文件
{
ifstream infile("hot.dat");
while (infile >> temp)
{
temp.num(num);
list_hot.push_back(temp);
num++;
}
infile.close();
infile.clear();
}
void savefile(list<Hotel> &list_hot) //写文件
{
ofstream outfile("hot.dat");
for(list<Hotel>::iterator li_hot=list_hot.begin();li_hot!=list_hot.end();li_hot++)
{
outfile<<*li_hot;
}
outfile.close();
outfile.clear();
}
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream outfile("abc.txt");
outfile<<"fdtgerqyeophy"<<endl;
outfile.close();
return 0;
}