Two dimension Vector / Reading Infile Writing Outfile

Afternoon Forum,

So what I need help with is writing a program that reads an input file, data.txt, stores the information in a two dimensional vector and then outputs the vector to an outfile, vector_data.txt.

The Data File Looks like this:

4 88 84 94 93
2 83 100
4 70 67 65 74
3 58 60 51

First Number( Number of tests ), Rest of the numbers are test scores.

My logic is to read the first number, use that number to fill the vector with the number of tests a student will have. I am not experienced with Vectors at all! Any help would be greatly appreciated. For some reason, when I use the command inFile >> numScores the first line of the datafile is completely skipped, when I output the variable, it's showing 2( which is the second line ). Here's what I have so far:

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
	
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <vector>

using namespace std;

double Avg(double);
double ClassAvg(double);
double classAverage;

vector< vector<int> > scores;

int main()

{
	char studentGrades[5] = { 'A', 'B', 'C', 'D', 'F' };
	double average, total = 0;
	int numScores;
	
	ifstream inFile;
	ofstream outFile;
	
	inFile.open("data.txt");
	outFile.open("vector_data.txt");
	
	while (!inFile.eof())
	{
		inFile >> numScores;
		cout << numScores;
		scores.push_back( vector<int>(numScores) );
		
		for(unsigned int count = 0; count < scores.size(); count++)
		{
			scores.push_back( vector<int>(count) );
			outFile << scores.at(0).at(0);
		}
		
		
	}
	
	inFile.close();
	outFile.close();
}	
Last edited on
Anybody?
Topic archived. No new replies allowed.