School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,132 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,931 people online right now. Registration is fast and FREE... Join Now!



flie handling

flie handling Rate Topic: -----

#1 pdkharkar  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 139
  • Joined: 19-January 09


Dream Kudos: 50

Posted 29 April 2009 - 03:47 PM

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......
Was This Post Helpful? 0
  • +
  • -


#2 eker676  Icon User is offline

  • C++ Programmer
  • Icon
  • View blog
  • Group: Contributors
  • Posts: 698
  • Joined: 18-April 09


Dream Kudos: 25

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.

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.
Was This Post Helpful? 1
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month