'How do I enter data from a file to a shared_ptr vector?
I have created a class (automobile) and two derived classes(car & truck) with their corresponding fields and methods.The program is supposed to accept input into an automobile shared_ptr vector(which contains a truck and car vector depending on the users choice) from a txt file . I've searched all over but I can't find anything helpful yet. I am only finding information as to how to input data into normal vectors. I hope you understand my code and what I'm trying to accomplish here.
class automobile
{
protected:
string colour;
void setcolor()
{
cout << "Colour: ";
cin >> colour;
}
string getcolor() { return colour; }
}
class car: public automobile
{
int numberOfDoors;
void setnumberOfDoors()
{
cout << "Number of doors: ";
cin >> numberOfDoors;
}
int getnumberOfDoors() { return numberOfDoors; }
}
class truck: public automobile
{
protected:
string numofTires;
void setNumOfTires()
{
cout << "Number of tires: ";
cin >> numOfTires;
}
int getNumOfTires() { return numOfTires; }
}
int main()
{
vector<shared_ptr<automobile>> autos;
char ch;
cout << endl;
cout << "Type(s) of automobile: " << endl;
cout << "a- truck" << endl;
cout << "b-sportscar" << endl;
cout << "c-next" <<endl;
cin>>ch;
//ignoring error handling
if(ch =='a')
{autos.push_back(make_shared<truck>());
//code to input data from file.
}
else if(ch =='b')
{autos.push_back(make_shared<car>());
//code to input data from file.
}
else
cout << "Done" << endl;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
