Quick question regarding text files and arrays

How would I go about taking data from a text file and writing the two separate columns to two separate arrays?

Here's the data:

2010 79
2597 90
2384 65
2496 87
2234 70
2697 92
2143 72
2003 88
2596 60
2890 71
2987 90
2536 85
2663 75
2742 88


And here are my arrays...
1
2
3
	const int SIZE = 20;
	int IDnum [SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	int Scores [SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for(int i = 0; file >> IDnum[i] >> Scores[i]; i++);
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
#include <windows.h>

#include <iostream>
#include <iterator>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> v1;
vector<int> v2;

struct Analyser {
	void operator ()(const int i) {
		if(v1.size() == v2.size()) {
			v1.push_back(i);
		} else {
			v2.push_back(i);
		}
	}
};

int main() {
	ifstream ifs("d.txt");
	istream_iterator<int> it(ifs);
	istream_iterator<int> endit;

	for_each(it, endit, Analyser());

	cout << "v1:" << endl;
	copy(v1.begin(), v1.end(), ostream_iterator<int>(cout, " "));
	cout << endl;

	cout << "v2:" << endl;
	copy(v2.begin(), v2.end(), ostream_iterator<int>(cout, " "));
	cout << endl;
	return 0;
}
Topic archived. No new replies allowed.