关于C++文件一个问题,求高手解答
#include<iostream>#include<stdlib.h>#include<fstream>constintsize=60;intmain(){usingn...
#include<iostream>
#include<stdlib.h>
#include<fstream>
const int size=60;
int main()
{
using namespace std;
char a[size];
ifstream women;
cin.getline(a,size);
women.open(a);
if(!women.is_open())
{cout<<"mei you da kai";
exit(EXIT_FAILURE);
}
double value;
double sum;
int count=0;
women>>value;
while(women.good())
{
++count;
sum+=value;
women>>value;
}
if(women.eof())
cout<<"end\n";
else if(women.fail())
cout<<"cuowu\n";
else cout<<"zhengque\n";
if(count==0)
cout<<"meiyou\n";
else{cout<<count<<endl;
cout<<"sum:"<<sum<<endl;
cout<<sum/count<<endl;
}
women.close();
return 0;
}
我想问的是如果,在文件aaa.txt中保存18 19 20 3个数字,如何才能里面的数值输出给value啊???才学文件弄不来。 展开
#include<stdlib.h>
#include<fstream>
const int size=60;
int main()
{
using namespace std;
char a[size];
ifstream women;
cin.getline(a,size);
women.open(a);
if(!women.is_open())
{cout<<"mei you da kai";
exit(EXIT_FAILURE);
}
double value;
double sum;
int count=0;
women>>value;
while(women.good())
{
++count;
sum+=value;
women>>value;
}
if(women.eof())
cout<<"end\n";
else if(women.fail())
cout<<"cuowu\n";
else cout<<"zhengque\n";
if(count==0)
cout<<"meiyou\n";
else{cout<<count<<endl;
cout<<"sum:"<<sum<<endl;
cout<<sum/count<<endl;
}
women.close();
return 0;
}
我想问的是如果,在文件aaa.txt中保存18 19 20 3个数字,如何才能里面的数值输出给value啊???才学文件弄不来。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询