c++文件输入输出问题
#include<iostream>#include<fstream>#include<cstdlib>usingnamespacestd;constintSIZE=60...
#include <iostream>
#include <fstream>
#include<cstdlib>
using namespace std;
const int SIZE = 60;
int main ()
{
char filename[SIZE];
ifstream infile;
int count,value;
char name[20];
cout<<"Enter file name: ";
cin.getline(filename,SIZE);
infile.open(filename);
if(!infile.is_open())
{
cout<<"打开失败!"<<endl;
exit(EXIT_FAILURE);
}
infile>>count;
if(count!=0)
{
cout<<count<<"ren"<<endl;
}
while(infile.good())
{
infile>>name;
cout<<"姓名:"<<name<<endl;
infile>>value;
cout<<"金额:"<<value<<endl;
}
if(infile.eof())
{
cout<<"读取完毕!"<<endl;
}
else if(infile.fail())
{
cout<<"读取失败!"<<endl;
}
else{
cout<<"其他错误!"<<endl;
}
infile.close();
}
为什么会多输出一行。 展开
#include <fstream>
#include<cstdlib>
using namespace std;
const int SIZE = 60;
int main ()
{
char filename[SIZE];
ifstream infile;
int count,value;
char name[20];
cout<<"Enter file name: ";
cin.getline(filename,SIZE);
infile.open(filename);
if(!infile.is_open())
{
cout<<"打开失败!"<<endl;
exit(EXIT_FAILURE);
}
infile>>count;
if(count!=0)
{
cout<<count<<"ren"<<endl;
}
while(infile.good())
{
infile>>name;
cout<<"姓名:"<<name<<endl;
infile>>value;
cout<<"金额:"<<value<<endl;
}
if(infile.eof())
{
cout<<"读取完毕!"<<endl;
}
else if(infile.fail())
{
cout<<"读取失败!"<<endl;
}
else{
cout<<"其他错误!"<<endl;
}
infile.close();
}
为什么会多输出一行。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询