#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char ch;
ofstream out1("hh1.txt");
ifstream in("hh1.txt");
ofstream out2("hh2.txt");
if(!out1||!in||!out2)
{
cout<<"cannot open the file.";
return 1;
}
out1<<"Jin Donghui is a fool";
out1.close();
while(in)
{
in.get(ch);
if(in) out2<<ch;
}
in.close();
out2.close();
return 0;
}
如果我把if(in) out2<<ch中的if(in)去掉,hh2.txt中的内容就会变成Jin Donghui is a fooll,多了一个l,这是为什么?
#include <fstream>
using namespace std;
int main()
{
char ch;
ofstream out1("hh1.txt");
ifstream in("hh1.txt");
ofstream out2("hh2.txt");
if(!out1||!in||!out2)
{
cout<<"cannot open the file.";
return 1;
}
out1<<"Jin Donghui is a fool";
out1.close();
while(in)
{
in.get(ch);
if(in) out2<<ch;
}
in.close();
out2.close();
return 0;
}
如果我把if(in) out2<<ch中的if(in)去掉,hh2.txt中的内容就会变成Jin Donghui is a fooll,多了一个l,这是为什么?