I'm trying to read information from a file and put the data into vectors of its appropriate type. For example: the file will have an int ID, string firstname, string lastname, double salary, int hours_per_week, and string work_position. All this data is separated by ";". I don't know how to read this file into the appropriate vectors: vector<int> ID, vector<string> fname, vector<string> lname, vector<double> salary, vector<int> hpw, vector<string> work. If anyone can help me figure this out, I would be very appreciated.
1) You can use struct so you won't have to deal with dozens of vectors:
1 2 3 4 5 6 7 8 9
struct Employee
{
int ID;
std::string firstname;
std::string lastname;
double salary;
int hours_per_week;
std::string work_position;
};
2) You can use getline() like that:
1 2 3 4 5 6 7 8
std::ifstream input("myfile.data");
std::string temp;
Employee person;
std::getline(input, temp, ';');//Note ';' here. It tells to read file content up to next ; in input
person.ID = std::stoi(temp);
std::getline(input, temp, ';');
person.firstname = temp;
//... And so on