请教高手续。。。
#include <fstream>#include <iostream>
#include <cstdlib>
using namespace std;
void copy(ifstream& in_stream, ofstream& out_stream)
{
char symbol;
int b,i;
int n;
double s;
// 外循环用于处理数据
do
{
s=0;n=0;
in_stream.get(symbol);
// 此循环用于获得学生姓名
while (true)
{
if(symbol >= '0' && symbol <= '9')
{
break;
}
out_stream.put(symbol);
in_stream.get(symbol);
}
in_stream.putback(symbol);
cout << "good.\n";
// 此循环用于处理一行的十个成绩
while (true)
{
in_stream >> b;
s=s+b;
n++;
out_stream << b << ' ';
in_stream.get(symbol);
if(symbol=='\n') //如果遇到换行就跳出循环
break;
}
cout << "very good.\n";
s = s / n;
out_stream << s<<endl;
}while(!in_stream.eof());
}
int main()
{
ifstream in;
ofstream out;
in.open("d:\\data2.txt");
if (in.fail())
{
cout << "Input file opening failed";
exit(1);
}
out.open("d:\\data3.txt");
if (out.fail())
{
cout << "Output file opening failed";
exit(1);
}
cout << "ok.\n";
copy(in, out);
in.close();
out.close();
return 0;
}
页:
[1]