C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C++ Expert!

Join 306,817 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,693 people online right now. Registration is fast and FREE... Join Now!




flie handling

 

flie handling

pdkharkar

29 Apr, 2009 - 03:47 PM
Post #1

New D.I.C Head
*

Joined: 19 Jan, 2009
Posts: 43


My Contributions
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......

User is offlineProfile CardPM
+Quote Post


eker676

RE: Flie Handling

29 Apr, 2009 - 05:20 PM
Post #2

C++ Programmer
Group Icon

Joined: 18 Apr, 2009
Posts: 652



Thanked: 68 times
Dream Kudos: 25
My Contributions
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.

CODE
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.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 11/20/09 10:13PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month