I have a variable declarations and a struct class as such
std::string fileName;
std::ifstream file(fileName);
passengerData data;
std::vector<passengerData> result;
struct passengerData
{
double arrivalTime;
int passengerClass;
double serviceClass;
};
This data is used in main like so
std::cout << "Please enter the name of the file: " << std::endl;
std::cin >> fileName;
while (file >> data.arrivalTime >> data.passengerClass >> data.serviceClass)
result.push_back(data);
for(passengerData i: result) {
enqueue(i.arrivalTime);
std::cout << "Passenger with index " << result[i] << " has entered the queue" << std::endl;
}
My occur at the last line of my for loop result[i]
where i get the error no operator "[]" matches these operands -- operand types are: std::vector<<error-type>, std::allocator<<error-type>>> [ passengerData ]
Im basically trying to do something like the following
Passenger 0 has entered the queue
Passenger 1 has entered the queue
Passenger 2 has entered the queue
etc....
Where 0 1 and 2 are the indexes of the records in the vector
It may also be a bit too much to ask but how may I transform this snippet into a int array rather than a vector?
ATTEMPTED FIX
for (int i = 0; i < result.size(); i++) {
enqueue(i.arrivalTime);
std::cout << "Passenger with index " << result[i] << " has entered the queue" << std::endl;
}
Recieve error expression must have class type
on line enqueue(i.arrivalTime);