getline() and array problem

Hi, This is my first post for a c++ issue, so if I didn't follow a proper format/guideline, I apologize.
I'm a beginner in c++ and I'm having problems with my assignment.
The thing is, we have to make user enter a file name, which contains student records i.e.
Amaris,Campbell,792025799,100,61,78,62,91,59
Amaya,Rodriguez,694315372,67,50,55,46,92,67
Ariel,Wilson,197735335,57,40,45,62,80,100
Artemis,Martinez,112070315,49,64,86,47,97,84
Ashling,Anderson,580510106,63,92,99,87,90,81
Asta,Taylor,151275537,43,64,76,42,86,54
Astra,Thomas,114387759,83,92,93,97,45,41
Astrid,Taylor,395519756,95,76,50,40,80,74
Belinda,Moore,724435231,47,59,69,96,97,98
Brenna,Martin,225447918,74,76,45,87,58,94
Cassandra,Jackson,405728917,61,48,58,86,83,76
Celina,Thompson,227402462,73,86,54,54,56,94
Danica,White,141460447,71,82,99,61,81,100
Darcy,Lopez,900669935,84,82,81,100,48,44
Desdemona,Lee,938146051,45,,85,88,92,73
Dysis,Gonzalez,955562835,47,93,96,53,57,44
Ebony,Harris,282185139,84,62,54,91,43,98
Eris,Clark,155338727,76,78

and that student record is then placed into a multidimensional array. The maximum rows of data is 200.
The first two column are string values and the last ones are int.
My problem is I am able to put everything into an array but some students did not receive all the grades therefore I need to make the rest of their line 0 values (i.e student name : Eris Clark, 155448727, 76, 68, 0,0,0,0)
but instead my program fills the next spot with the next student instead of 0.
can you guys guide me how to get that done?

or Even if you have a better way to do this please guide me to it?
I am trying to put everything into a multidimensional array where every new row is a new student, and for any student with incomplete grades it should be a 0 int value.
I need to then later be able to sort and search that file for student records.
I look into vectors but unfortunately we did not hit that chapter yet in class. but I can always try to learn it on my own with some help.
what would be the best approach, thank you.

here's my code 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
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <conio.h>
#include "A4.h"

using namespace std;


void getFileName()
{
		cout << "Enter the desired Filename (ie. grades.dos)" << endl;
		cin >> fileName;

		fin.open(fileName);

			if (!fin)
			{
				cout << "File name does not exist\nPlease retry again" << endl;
				exit (1);
			}
}

void makeArray()
{
	while(!fin.eof() && i!=200)
	{
		getline(fin, line);
		istringstream iss(line);
		for (j; !iss.eof() && j<= 9; j++)
		{
			getline(iss, word, ',');
			myArray[i][j]=word;
			cout << myArray[i][j];
		}

		i++;
		j=1;
		cout << endl;

	}	
}

int main()
{
string fileName;
fstream fin;
int i = 1;
int j = 1;
string myArray[200][9]={"0"};
string word;
string line;
	getFileName();
	makeArray();
	system("PAUSE");
	return 0;
}
Last edited on
Topic archived. No new replies allowed.