Dear Friends:

The following is a tiny program to illustrate "opening a file" and save the results to another file. I have done this successfully. However, I want to do a further step. I want to input such as 1000 groups data, instead of input them manually, now, I want to input them by a file and calculate them one by one automatically. The following program I wrote only is able to input once. Is any expert know how to do that?

In order to say more clearly, the following also contains "test" and "test1". My purpose is to also calculate the second and third row of the "test" file and put the results in "test1:

"test" file content:

1.1 2.2 3.2
4.2 5.5 6.5
7.2 8.1 9.1

"test1" file content:
1.1 2.2 3.2 6.6

Program:

#include<iostream.h>
#include<fstream.h>

main()
{
float a,b,c,d;

ifstream in("test");
ofstream out("test1");
if(!in) {
cout<<"cannot open file.";
return 1;
}

if(!out) {
cout<<"cannot open file.";
return 1;
}

in >>a>>b>>c;
d = a + b + c;
out << a <<" " << b << " " << c << " " << d;
in.close();
out.close();
return 0;
}