C++ 这里应该怎样使用feof()函数。
#include<iostream>#include<fstream>usingstd::cout;usingstd::cin;usingstd::endl;usings...
#include <iostream>
#include<fstream>
using std::cout;
using std::cin;
using std::endl;
using std::ofstream;
using std::ifstream;
int main(){
int year;
ifstream inFile("in.txt");
ofstream outFile("out.txt");
while(inFile>>year){
if((year%4==0 && year%100!=0)||(year%400==0)){
outFile<<year<<" is a leap year"<<endl;
}
else
outFile<< year<<" is not a leap year"<<endl;
}
return 0;
}
Please input the data from a file instead of from keyboard,and save the result
into a file. You can use class ifstream and
ofstream,and judge the end of a file by calling
feof()。 展开
#include<fstream>
using std::cout;
using std::cin;
using std::endl;
using std::ofstream;
using std::ifstream;
int main(){
int year;
ifstream inFile("in.txt");
ofstream outFile("out.txt");
while(inFile>>year){
if((year%4==0 && year%100!=0)||(year%400==0)){
outFile<<year<<" is a leap year"<<endl;
}
else
outFile<< year<<" is not a leap year"<<endl;
}
return 0;
}
Please input the data from a file instead of from keyboard,and save the result
into a file. You can use class ifstream and
ofstream,and judge the end of a file by calling
feof()。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询