ofstream问题
#include<iostream>
#include<fstream>
#include<stdlib.h>
using namespace std;
int main(){
ofstream out("text.txt");
if (out.is_open()){
out << "1998\n";
out << "1999\n";
out << "2000\n";
out << "2001\n";
out << "2002\n";
out << "2003\n";
out << "2004\n";
out << "2005\n";
out << "2006\n";
out << "2007\n";
out << "2008\n";
out << "2009\n";
out << "2010\n";
out << "2012\n";
out << "2013\n";
out.close();
}
int year[20];
char buffer[5];
ifstream in("text.txt");
if (!in.is_open()){
cout << "Error opening file";
exit(1);
}
while (!in.eof()){
int num = 0;
in.getline(buffer,5);
year[num] = atoi(buffer);
ofstream out1("text1.txt",ios::out);
if (out1.is_open()){
if (year[num] % 4 == 0 && year[num] % 100 != 0 || year[num] % 400 == 0){
cout << year[num] << " is a leap year\n";
out << year[num] <<" is a leap year\n";
out.close();
}
else{
cout << year[num] << " is not a leap year\n";
out1 << year[num] << " is not a leap year\n";
out1.close();
}
}
num++;
}
return 0;
}
请问 我最后text1.txt里只有一句 0 is a leap year.是为什么...