#include
#include
#include
using namespace std;
int main()
{
char ifname[16],ofname[16];
ifstream instream;
ofstream outstream;
cout << "请输入要打开的文件名:";
cin >> ifname;
cout << "请输入要输出的文件名:";
cin >> ofname;
instream.open(ifname);
if(instream.fail())
{
cout << "文件打开失败!" << endl;
exit(1);
}
outstream.open(ofname);
if(outstream.fail())
{
cout << "文件打开失败!" << endl;
exit(1);
}
double next;
int sum=0,i=0,j=0,a[100],temp,b;
while(instream >>next)
{
if(int(next)==next)
{
outstream << next << endl;
a[i]=next;
i++;
b=i;
sum=sum+next;
}
}
for(i=0;i for(j=i;a[j]>a[j+1]&&j>=0;j--)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
outstream << "这些整数由小到大排列为:" << endl;
for(i=0;i {
outstream << a[i] << endl;
}
outstream << "所有整数的和为:" << sum << endl;
instream.close();
outstream.close();
return 0;
}
顺便帮忙改进下程序,使之能找出包含任意字符的文件中的int类型数字
--------------------next---------------------
阅读(1061) | 评论(0) | 转发(0) |