#include
#include
#include
using namespace std;
ofstream outfile;
void writeLog()
{
outfile.open("C:\\myfile.txt", ios::app);
if(!outfile) //检查文件是否正常打开//不是用于检查文件是否存在
{
cout<<"abc.txt can't open"<<endl;
abort(); //打开失败,结束程序
}
else
{
outfile << "world" << endl;
outfile.close();
}
}
{
outfile.open("C:\\myfile.txt", ios::app);
if(!outfile) //检查文件是否正常打开//不是用于检查文件是否存在
{
cout<<"abc.txt can't open"<<endl;
abort(); //打开失败,结束程序
}
else
{
outfile << "world" << endl;
outfile.close();
}
}
void writeLog2()
{
outfile.open("C:\\myfile.txt", ios::app);
if(!outfile) //检查文件是否正常打开
{
cout<< "abc.txt can't open"<< endl;
abort(); //打开失败,结束程序
}
else
{
outfile << "Write log2" << endl;
outfile.close();
}
}
{
outfile.open("C:\\myfile.txt", ios::app);
if(!outfile) //检查文件是否正常打开
{
cout<< "abc.txt can't open"<< endl;
abort(); //打开失败,结束程序
}
else
{
outfile << "Write log2" << endl;
outfile.close();
}
}
int main(int argc, char* argv[])
{
writeLog();
writeLog2();
printf("Hello World!\n");
return 0;
}
{
writeLog();
writeLog2();
printf("Hello World!\n");
return 0;
}