#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
int main()
{
char filename[50];
char buffer[255];
cout << "Please input the filename :";
cin >> filename;
cin.getline(buffer,255);
cout << endl;
ofstream fout2(filename,ios::in);
if(!fout2)
{
ofstream fout(filename,ios::out);
cout << "There isn't the " << filename << " for creating." << endl;
time_t timep;
time (&timep);
fout << asctime(gmtime(&timep));
fout << "Hello world !!!!" << endl;
cout << "Please enter text for the file:";
cin.getline(buffer,255);
fout << buffer << endl;
fout.close();
cout << "\nOpening the file " << filename << " in read mode..." << endl;
ifstream fin(filename);
if(fin)
{
cout << "Current file contents;" << endl;
char ch1;
while(fin.get(ch1))
cout << ch1;
cout << "\n*****End of file contenfs.****" << endl;
}
fin.close();
}
else
{
cout << " zxlhwq_1 " << endl;
cout << "\nOpening the file " << filename << " in append mode..." << endl;
ofstream fout1(filename,ios::app);
if(!fout1)
{
cout << "Unable to open the " << filename << " 1 for appending." << endl;
}
else
{
cout << " zxlhwq_2 " << endl;
cout << "\nAppend text for the file: ";
cin.getline(buffer,255);
fout1 << buffer << endl;
fout1.close();
cout << "\nOpening the file " << filename << " in again read mode..." << endl;
ifstream fin1(filename);
if(!fin1)
{
cout << "Unable to open the " << filename << " 2 for appending." << endl;
}
else
{
cout << " zxlzxl " << endl;
cout << "\nHere's the contents of the file:" << endl;
char ch2; while(fin1.get(ch2))
cout << ch2;
cout << "*********End of file contents.******" << endl;
fin1.close();
}
}
}
system("Pause");
return 0;
}
creatfile.zip_creatfile
版权申诉
118 浏览量
2022-09-24
02:41:58
上传
评论
收藏 801B ZIP 举报
APei
- 粉丝: 63
- 资源: 1万+
最新资源
- 基于matlab实现配电网三相潮流计算方法,对几种常用的配电网潮流计算方法进行了对比分析.rar
- 基于matlab实现配电网潮流 经典33节点 前推回代法潮流计算 回代电流 前推电压 带注释.rar
- 基于matlab实现模拟退火遗传算法的车辆调度问题研究,用MATLAB语言加以实现.rar
- 基于matlab实现蒙特卡洛的的移动传感器节点定位算法仿真代码.rar
- 华中数控系统818用户说明书
- 基于matlab实现卡尔曼滤波器完成多传感器数据融合 对多个机器人的不同传感器数据进行融合估计足球精确位置.rar
- 基于matlab实现进行简单车辆识别-车辆检测.rar
- 基于JSP物流信息网的设计与实现
- 基于matlab实现车牌识别程序,和论文,自己做的,做毕业设计的可以看看 .rar
- Windows系统下安装与配置Neo4j的步骤
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈