为了账号安全,请及时绑定邮箱和手机立即绑定

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.是为什么...

正在回答

举报

0/150
提交
取消
C++远征之封装篇(上)
  • 参与学习       103410    人
  • 解答问题       701    个

封装--面向对象的基石,本教程力求帮助小伙伴们即学即会

进入课程

ofstream问题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信