Below is the file I need to extract data from.
auto1
engine: gasoline
max_speed: 250
engine_cc: 1980
avg_consumption_urban: 11
avg_speed_urban: 50
avg_consumption: 8
avg_speed: 100
auto2
engine: diesel
max_speed: 230
engine_cc: 1600
avg_consumption_urban: 9
avg_speed_urban: 50
avg_consumption: 6
avg_speed: 80
auto3
engine: hybrid
max_speed: 190
engine_cc: 1450
avg_consumption_urban: 7
avg_speed_urban: 50
avg_consumption: 4
avg_speed: 90
I need to create three auto objects, auto1, auto2, auto3.
The code I have so far:
[my code] http://pastebin.com/2TMhQX9b
I need to modify this method to skip over the "engine:", "max_speed:" ... etc and get the information that is after those attribute titles and insert the respective value in the corresponding attribute.
Also I need to find a way for the compiler to know for example when creating auto2 to get the information for auto2 and not auto1 from the file
friend ifstream& operator>>(ifstream& in, Auto &a)
{
delete[]a.engine;
a.engine = new char[10];
in >> a.engine;
in >> a.max_speed;
in >> a.engine_cc;
in >> a.avg_consumption_urban;
in >> a.avg_speed_urban;
in >> a.avg_consumption;
in >> a.avg_speed;
return in;
}
This question is different from my previous question. Here I need to find out how I can get my data from the file and insert it into multiple variables.