为什么我第二个ofstream流输出不到文件上?
void Diary::Creat_New_Diary(string Account){
Diary a;
system("cls");
string day,month,year;
string date;
string diary;
string str = "SaveDiary";
string FileName = Account + str;
ofstream *fouts = new ofstream;
cout << "\t\t年:";
cin >> year;
cout << "\t\t月:";
cin >> month;
cout << "\t\t日:";
cin >> day;
date = year + "-" +month + "-" +day;
Account += date;
fouts->open(Account.c_str());
if(fouts->fail())
{
cout << "新建日记失败"<<endl;
exit(1);
}
*fouts <<"\t\t\t"<< date <<endl;
cin >> diary;
*fouts <<diary;
a.Save_Diary(FileName,date);
fouts->close();
system("cls");
}
void Diary::Save_Diary(string FileName,string date)
{
ofstream *fout = new ofstream;
fout->open(FileName.c_str());
if(fout->fail())
{
cout << "保存日记失败"<<endl;
exit(1);
}
*fout << date;
cout << "保存成功";
Sleep(1000);
}
第一个函数中调用了第二个函数,第一个保存日记内容可以保存进Account文件,为什么第二个函数的日期就不能保存进FileName文件里?文件是建立了,但是里面空白,没有东西。这是怎么回事?
第2个函数中缺少一个 fouts->close();来关闭FileName文件吧。。。 elvo 发表于 2014-5-23 23:44 static/image/common/back.gif
第2个函数中缺少一个 fouts->close();来关闭FileName文件吧。。。
对哦,天,这都忘了- -。。。。低级错误。。哎哎
页:
[1]