Reading from a text filed and doing operations

Okay, so as a side project Im making a program that will keep track of standings in a league. It keeps track of the wins/loss/tiebreaker of every player and saves that to a text file. The program also has an option to display the standings.

What im currently stuck on is updating the stats. So lets say I input week 1 stats for user one. His record is 10-5-2, that record gets saved to a text file. Then lets say week 2 he goes 11-4-2. I would like to be able to have the program add up his total record. So it would read the 10-5-2 from week 1, and add the 11-4-2 to it. Then output that total to the file (21-9-4)

So here is my current code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Predictions calculator and refresher on C++

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main ()
{
	string name = "";
	int a;
	int b = 3;
	int loss;
	int wins;
	int tb;
	string name2 = "";
	int loss2;
	int wins2;
	int tb2;

  cout << "          Welcome To the 2011 Football Predictions Calculator. \n" << " \n" << " \n";
  cout << "What would you like to do? \n \n";
  cout << "To edit standings press 1. To view standings press 5.\n";
  cin >> a;
  cout << "\n";
  if(a < 3)
  {
  cout << "What is the first users name? \n";
  cin >> name;
  cout << "What is " << name << "'s amount of wins \n";
  cin >> wins;
  cout << "What is " << name << "'s amount of losses? \n";
  cin >> loss;
  cout << "What is " << name << "'s tie breaker score? \n";
  cin >> tb;
  cout << name << " 's record is " << wins << " - " << loss << " - " << tb << "\n";
 
  ofstream myfile;
  myfile.open ("standing.txt");
  myfile << "2011 Football Prediction Standings\n" << name << "      " << wins << " - " << loss << " - " << tb << " \n";
  cout << "What is the second users name? \n";
  cin >> name2;
  cout << "What is " << name2 << "'s amount of wins \n";
  cin >> wins2;
  cout << "What is " << name2 << "'s amount of losses? \n";
  cin >> loss2;
  cout << "What is " << name2 << "'s tie breaker score? \n";
  cin >> tb2;
  cout << name2 << " 's record is " << wins2 << " - " << loss2 << " - " << tb2 << "\n \n \n \n \n";
  
  myfile  << name2 << "      " << wins2 << " - " << loss2 << " - " << tb2 << " \n";
  myfile.close();
  ;}
  else
  { 
 // std::cout << "Press ENTER to continue...";
  //std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
 


  //Reading from file and outputting
   int length;
  char * buffer;

  ifstream is;
  is.open ("standing.txt", ios::binary );

  // get length of file:
  is.seekg (0, ios::end);
  length = is.tellg();
  is.seekg (0, ios::beg);

  // allocate memory:
  buffer = new char [length];

  // read data as a block:
  is.read (buffer,length);
  is.close();

  cout.write (buffer,length);

  delete[] buffer;
  ;}
  system("pause");
  return 0;
  }

I guess my question is how do I go about reading the text file, getting the records as an integer. Once I can declare the records as an integer I know how to get the program to do the math and re-write to the .txt file.

Im pretty sure im going to have to rewrite the majority of the program to do it, but im pretty lost, and blatantly new to C++.
Thanks
Topic archived. No new replies allowed.