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
|
ifstream readTrain(TRAIN_FILE);
if (!readTrain.is_open())
{
throw runtime_error("Error opening trains data file");
}
else
{
//train id, deptStation, destination, deptTime, arrivalTime, maxSpeed
string line, id, dStation, aStation, dTime, aTime;
double mSpeed = 0;
// various types of vehicles attached to the train
int typ = 0;
while (getline(readTrain, line))
{
istringstream iss(line);
iss >> id >> dStation >> aStation >> dTime >> aTime >> mSpeed;
while (iss >> typ) // trying to read the rest of the line. MY PROBLEM
{
VehicleType type = static_cast<VehicleType>(typ);
vehType.push_back(type);
//trVeh.insert({id, vehType}); // map<string(trainID), vector<VehicleType>>
}
trVeh.insert({id, vehType}); // map<string(trainID), vector<VehicleType>>
vehType.clear(); // make an anew vehType
int d = intFromStringTime(dTime), ar = intFromStringTime(aTime);
double sp = mSpeed;
//void Train::setValues(const string & pid, string dep, string arr, int dTime, int aTime, double mSpeed)
setValues(id, dStation, aStation, d, ar, sp);
// make train object
//Train(string id, Destination d, int dTime, int aTime, double mSpeed, vector<VehicleType> types)
// Destination(a class) holds depature and arrival stations
Train t(id, spur, d, ar, sp, vehType);
// push it into trains vector
trains.push_back(t);
}
}
|