Hi yall,
So for a practice test, there is a problem that states:
Assume that a vector of Coaster Objects has already been declared and filled with Coaster objects created from the contents of the file:
vector<coaster> rides; // already filled with coaster objects.
It goes on to ask a different question but I was more confused by how he was able to make a vector of type(coaster) that took a string and two integers.
So my question is how do I make a vector that takes in for [i] a string(name of the coaster) and two integers one for wait time and the other for the puke chance and how do I read it in from the text file?
Luckily, the question isn't asking you to do that. It's asking you to make a vector of Coaster objects. Every single item in that vector is of the same type - Coaster.
You haven't shown us the definition of Coaster, but I assume it's a struct (or a class - in C++, they're the same thing), whose members are a string and two integers.
ifstream fin("Coaster.txt");
std::string name;
int wait;
int puke;
vector<Coaster> coasters;
whlie (fin >> name >> wait >> puke)
{
// name, wait, and puke have been filled with values from the file
coasters.push_back(Coaster(name, wait, puke));
}