Усовершенствовать код с++. Подскажите, пожалуйста, как будет правильнее записывать файл такой структуры. Подобных классов много. Получается для записи каждой строки вызываю метод из каждого класса. Как осуществить запись одним методом
function.h
class Station
{
public:
std::string station_name;
std::string rec_dew;
std::string year;
CreateFileLibrary_API void writeinfofStation(std::ostream &file);
};
class InfDiscretChanel
{
public:
int DN;
std::string ch_id;
std::string ph;
std::string ccmb;
int y;
CreateFileLibrary_API void writefourthline (std::ostream &file);
};
function.cpp
void Station::writeinfofStation(std::ostream &file)
{
file<<station_name<<","<<rec_dew<<","<<year<<"\n";
}
void InfDiscretChanel::writefourthline(std::ostream &file){
file << DN << ","<<ch_id.c_str()<< "," <<ph.c_str()<< ","<<ccmb.c_str()<< ","<<y<< "\n";
}
main.cpp
ofstream efile("file.cfg");
CreateFileLibrary::Station infStation = {"name","1","2001"};
infStation.writeinfofStation(efile);
CreateFileLibrary::InfDiscretChanel d1 = {1,"2_2"," "," ",0};
CreateFileLibrary::InfDiscretChanel d2 = {2,"3_3"," "," ",0};
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости