请问为什么加上 !cin.eof() 后结果就不对了呢
EXAMPLE 1:
int main(void){ ifstream infile; ofstream outfile; infile.open("E:\\IN.TXT"); if (!infile) return -1; outfile.open("E:\\OUT.TXT"); if (!outfile) return -1; string str; while(infile >> str, !infile.eof()) //这里有 !infile.eof() { outfile << str <<endl; infile.clear(); } infile.close(); outfile.close(); }int main(void){ ifstream infile; ofstream outfile; infile.open("E:\\IN.TXT"); if (!infile) return -1; outfile.open("E:\\OUT.TXT"); if (!outfile) return -1; string str; while(infile >> str) //这里没有 { outfile << str <<endl; infile.clear(); } infile.close(); outfile.close(); }