Problem with reading from a file and placing into parallel vector

My program is supposed to read data from a text file and place the data it holds into separate vectors depending on what piece of data it holds. The text file can be seen here (right click link and save as [change .dat to .txt if needed])

The program correctly reads in the first 3 columns of data (player number, first name, last name), however when I try to call


I get an error, and I have no idea how to fix it. I believe that it's due to FGM_Vector being a 2d vector, but as I said, I have no clue where to go from here, so any ideas would be helpful. Please note: I'm not simply asking for an answer here, I want to know why this happened and how to fix it, so instead of simply posting a solution, please attempt to explain to me why it works. Thanks!

Here's my code:

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
ifstream infile;"finalfour.dat");

if (
return 0; // Error-checking against file that cannot be opened

vector<string> FN_Vector; // Player First Name Vector
vector<string> LN_Vector; // Player Last Name Vector
vector<int> Plynum_Vector; // Player Number Vector
vector<vector<int>> TPA_Vector; // Three point attempts vector
vector<vector<int>> TPM_Vector; // Three points made vector
vector<vector<int>> FGA_Vector; // Field Goal attempts vector
vector<vector<int>> FGM_Vector; // Field Goals made vector
vector<vector<int>> FTA_Vector; // Free Throw Attempts vector
vector<vector<int>> FTM_Vector; // Free Throws Made fector

int player_num; // player number
string first_name;
string last_name;
int fld_gl_mde; // field goals made
int fld_gl_attp; // field goals attempted
int three_pnt_made; // 3 point shots made
int three_pnt_attp; // 3 point shots attempted
int free_thr_made; // free throws made
int free_thr_attp; // free throws attempted
int ctr = 0; // iteration counter for the following while loop

while (!infile.eof())
infile >> player_num >> first_name >> last_name >> fld_gl_mde >> fld_gl_attp >> three_pnt_made >> three_pnt_attp >> free_thr_made >> free_thr_attp;

//cout << Plynum_Vector[ctr] << " " << FN_Vector[ctr] << " " << LN_Vector[ctr] << endl;

//cout << FGM_Vector[ctr][ctr] << endl;


return 0;
Last edited on
Topic archived. No new replies allowed.