Problems loading a text file into a struct of vectors
I'm trying to open a text file and load its contents into a struct of vectors. The text file looks something like this...
638912 [email protected] 555-555-3827 Gibson, Martha Elizabeth
582841 [email protected] 555-555-4591 Williams, Henry James III
719472 [email protected] 555-555-6183 Anderson, Tina Marie
The first number is stored in a vector of doubles, and the other 4 (email, phone num, first name, and last name) will be in string vectors.
Each vector is a member of a struct.
The program compiles fine but gives a segmentation fault error when I try to run it. My code for main() looks like this...
Code:
#include <iostream>
#include <fstream>
#include <algorithm>
#include "proj08.database.h"
using namespace std;
int main(int Argc, char *Arg[]){
int i = 0;
Student stuInfo;
ifstream inFile;
ofstream outFile;
if(Argc != 2){
cout << "Improper amount of arguments." << endl;
}
inFile.open("project08.sample.students.old");
while(!inFile.eof()){
inFile >> stuInfo.studentNum[i] >> stuInfo.email[i] >> stuInfo.phoneNum[i] >>
stuInfo.studentLastName[i] >> stuInfo.studentFirstName[i];
i++;
}
return 0;
}
The code in my header where the struct is contained looks like this...
Code:
#ifndef DBASE_
#define DBASE_
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Student{
vector<double> studentNum;
vector<string> studentFirstName;
vector<string> studentLastName;
vector<string> email;
vector<string> phoneNum;
};
#endif
I am unsure of what exactly I am doing wrong here and any help would be appreciated. Thanks!