I have a problem, I got a file with different cities and road, I did a class called Ville (city in french) and a class called Route (Road in french) and I need to put all my Ville into a vector of Ville and all my route into a vectof of route
Ville constructor is called like that:
Ville *myCity = new Ville("myCity");
and the road constructor:
Route *myRoad = new Road("myRoad",400, 130, myCity1, myCity2);
where the argument are the name of the road, the size, the maximum speed, and the two cities which are link by the road.
The file look like:
< ville>
Paris
Berlin
...
< /ville>
< route>
A0 400 130 Paris Berlin
...
</route>
I did that for the data extraction:
std::string element;
int statut = 0;
while(fichier >> element)
{
if(element == "</ville>" || element == "</route>")
{
statut = 0;
fichier >> element;
}
if(element == "<ville>" || statut == 1)
{
if(statut == 0)
{
fichier >> element;
}
cout << "Ville: " << element << endl;
statut = 1;
}
if(element == "<route>" || statut == 2)
{
if(statut == 0)
{
fichier >> element;
}
cout << "Route: " << element;
fichier >> element;
cout << " Taille: " << element;
statut = 1;
fichier >> element;
cout << " Speed: " << element;
fichier >> element;
cout << " Relie: " << element;
fichier >> element;
cout << " à " << element <<endl;
statut = 2;
}
}
}
else
{
cout << "Error: Can't open the file" << endl;
}
I'm looking for a method that allow me to do something like:
Ville *element = new Ville (element);
Or should I change the way that I extract data to be easily transform into object?