좋아요. 그래서이 두 구조체를 txt 파일에 저장하는 함수로 보냅니다.파일에 구조체 정보 쓰기
struct Cost
{
double hours;
double cost;
double costFood;
double costSupplies;
};
struct Creatures
{
char name[50];
char description[200];
double length;
double height;
char location[100];
bool dangerous;
Cost management;
};
이 부분은 혼란스럽고,이 구조의 각 줄을 파일에 쓰는 방법을 모르겠다. 누군가 나에게이 일을 어떻게 설명 할 수 있습니까?
file.open(fileName, ios::out);
if (!file)
{
cout << fileName << " could not be opened." << endl << endl;
}
else
{
fileName << c.name
<< c.description
<< c.lenght
<< c.height
<< c.location
<< c.dangerious
<< c.management.hours
<< c.management.cost
<< c.management.costFood
<< c.management.costSupplies;
file.close();
cout << "Your creatures where successfully save to the " << fileName << " file." << endl << endl
<< "GOODBYE!" << endl << endl;
}
}
위의 두 구조에 대해 연산자 <<를 써야합니다. 그래서 당신은 당신의 프로그램에 있기를 원하는대로 사용할 수 있습니다. –
나는 당신이 의미하는 바를 편집했다. – Baalzamon