//文件的读写 #include <fstream> void wenjian1()//文件的打开,读取,关闭 ios::in 读取文件 ios::out 写文件 ios::app 写文件的时候不覆盖原文件 { char * filename=""; char * filename1=""; ifstream readfile(filename,ios::in);//读取文件时的打开方式方式1 // ifstream readfile1;//读文件对象 // readfile1.open(filename,ios::in);//读取文件时的打开方式2 ofstream readfile_w(filename1,ios::out|ios::app);//写文件时的打开方式方式1 // ofstream readfile_w1; // readfile_w1.write(filename,ios::out);//写文件时的打开方式方式2 //判断文件打开是否成功 if (!readfile) { cout<<"打开文件失败"<<endl; } //读文件 char ch; while (readfile.get(ch))//将一个文件内容,另一个文件内 { cout<<ch;//读取文件方式 .get() readfile_w.put(ch);//写入文件方式 .put() } //关闭文件 readfile.close(); readfile_w.close(); }
c++中文件的读写
最新推荐文章于 2024-08-20 21:41:54 发布