File input and output with funtions

After trying everything I can think of I still cannot get anything to read from my file and after reading, print to my second file. I need the function SetData(); to read from MP4election.txt and then have print1(); display similar info into MP4electionResults. I am drawing a blank so bad it hurts. Any and all help would be awesome!

Any questions please ask. and yes I know it looks like a wreak but after playing with it for over an hour it slowly looked worse.

I need to store the read info into dynamic arrays and this book also says I need to overload but looking at it I don't see why.

Class

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
 #include <iostream>
#include <string>
#include <fstream>
using namespace std;



class Election
{
private:
	
	char *NArr[10];
	int *v1arr[10];
	int *v2arr[10];
	int *v3arr[10];

public:
	//Election();
	void GetNumberofLines();
	void SetData();
	void print1();
	void print2();
	void print3();

};


void GetNumberofLines()
{
	int counter = 0;
	string line = "";

	while (getline(cin, line))
		{
		    ++counter;
		}
}

void Election::SetData()
{
	
	 int i = 0;
  
	while(!cin.eof())
	{
		
		cin >> *NArr[i] >> *v1arr[i] >> *v2arr[i] >> *v3arr[i];
		++i;
	}

	
	
}

void Election::print1()
{
	

  

	for(int j = 0; j < 10; j++)
	{
		cout << *NArr[j] << endl;


	}

	
}


Main

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#include "MP4Header.h"

void main()
{

	fstream myfile("MP4electionResults.txt", ios::in | ios::out);
	ofstream fout;
	ifstream fin;

	myfile.open ("example.txt");

	Election chart1;

	chart1.SetData();
	chart1.print1();
	

	myfile.close();

	system("pause");
}


Txt file i much read from

1
2
3
4
5
6
7
Lincoln 120 300 400
Parks 100 500 250
Shakespeare 0 30 50
Ghandi 250 100 40
Ashe 300 50 175
Rodriguez 87 118 320
Curie 284 0 112
Last edited on
SOooo?
Topic archived. No new replies allowed.