Binary file

Declare a structure Animals that has  breed type, and price as its members.   Declare a variable of the Animals and assign appropriate values to the variables.   Write the variable to a binary file , "Animals.txt".
Here is my solution, unless the assignment states more.
1
2
3
4
5
6
7
8
9
10
11
struct Animals
{
    string breedType;
    double price;
} animal;

animal.breedType = "cat";
animal.price = 200;

ofstream outFile("Animals.txt", ios::in | ios::binary);
outFile << animal.breedType << ' ' << animal.price << endl;
Last edited on
Topic archived. No new replies allowed.