I am writing a program to update and store the details of th batsman and the bowler to a file
the file should be kept updating every time we run program for example
if number of matches of a person is 12 and strike rate is 95 then after execution of program, number of matches should increment and new strike rate should be calculated using the older and new innings...
please tell me how to implement it in a file......
flie handling
Page 1 of 1
flie handling
#2
Posted 29 April 2009 - 05:20 PM
I am going to assume that the number of matches and the strike rate are on separate lines in the file. Also the number of matches is first.
That is one way of doing it.
ifstream infile("thefile.txt", ios::in);
int data[2];
infile >> data[0];
infile >> data[1];
data[0] += number_of_matches;
data[1] // calculate strike rate
infile.close();
ofstream outfile("thefile.txt", ios::out | ios::trunc);
outfile << data[0] << endl << data[1];
outfile.close();
That is one way of doing it.
Page 1 of 1

Start a new topic
Add Reply





MultiQuote

| 


