0
我是C++中的一个begginer,我需要制作一些需要从文件中读取的汽车相关类。在其中一个中,我想使用enum 我的类看起来是这样的:如何从文件中读取时使用枚举
enum engines{ gasoline, hybrid, diesel };
class Automobil
{
const int id;
char *model;
engines engine;
int max_speed;
int engine_cc;
float avg_consumption_urban;
float avg_consumption;
float avg_speed_urban;
float avg_speed;
}
,我需要重载>>操作员从文件中读取的对象,但是当我的引擎做了,我有错误。我如何仍然保留枚举并从文件中读取?
friend ifstream& operator>>(ifstream& input, Automobil &a)
{
delete[] a.model;
input >> a.model;
input >>a.engine; //error here
input >> a.max_speed;
input >> a.engine_cc;
input >> a.avg_consumption_urban;
input >> a.avg_speed_urban;
input >> a.avg_consumption;
input >> a.avg_speed;
return input;
}
你为什么要删除a.model? – ForeverStudent
我建议在网上搜索例子。我最近看到一个类似的问题发布。 –
我复制了所有从其他过载是没有必要的..我不知道什么搜索了,因为我没有找到与我的问题相关的例子.. –