In the book I'm reading, It started talking about binaries, and how we can output to a binary file similarly to how we can output to a text file. So I started reading more and wanted to give it a try; however, I've ran into what seems like a simple issue, but one that I'm not understanding properly considering my lack of understanding when it comes to binaries files.
So lets say I created a structure, and a function. Like the following.
struct celebrities
{
char name[15];
char lastName[15];
};
void BinaryCreation(celebrities );
int main()
{
celebrities actors = { "Denzel", "Washington" };
BinaryCreation( actors);
system("pause");
}
Now, I'll create a binary file:
void BinaryCreation(celebrities actors)
{
fstream file;
file.open("binaryfile.txt", ios::binary | ios::out);
Now, in the book it states that I should write something like the following to output it into binary:
file.write(address, size)
Which is where it gets confusing seeing as how if I have a structure, how exactly do I do that? I tried the following:
file.write(&actors.name, sizeof(actors.name));
file.write(&name, sizeof(name));
Also tried reinterpret cast. I also did the following
file.write(actors.name, sizeof(actors.name));
which worked in the sense of no errors, but it would output to file in text form (ASCII).
I'm sure this is very simple, and I'm overlooking something, but at the moment I can't figure it out.