65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream ifile;
ofstream ofile;
char ch;
ifile.open("TEST.txt");
if(!ifile){
cout<<"没有找到指定的文件"<<endl;
return 0;
}
ofile.open("TEST1.txt");
if(!ofile){
cout<<"无法建立以TEST1.txt命名的文件";
return 0;
}
while(true){
ifile>>ch;
cout<<ch;
ofile<<ch;
if(ifile.eof()) {
ifile.close();
ofile.close();
return 0;
}
}
}
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream ifile;
ofstream ofile;
char ch;
ifile.open("TEST.txt");
if(!ifile){
cout<<"没有找到指定的文件"<<endl;
return 0;
}
ofile.open("TEST1.txt");
if(!ofile){
cout<<"无法建立以TEST1.txt命名的文件";
return 0;
}
while(true){
ifile>>ch;
if(ifile.eof()) //注意这个函数,是读到文件结尾时,返回真.
{
ifile.close();
ofile.close();
return 0;}
cout<<ch;
ofile<<ch;
}
}
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream ifile;
ofstream ofile;
char ch;
ifile.open("1.txt");
if(!ifile){
cout<<"没有找到指定的文件"<<endl;
return 0;
}
ofile.open("file1.txt");
if(!ofile){
cout<<"无法建立以TEST1.txt命名的文件";
return 0;
}
while(true){
ifile>>ch;
if(ifile.eof()) {
ifile.close();
ofile.close();
return 0;}
cout<<ch;
ofile<<ch;
}
}