#include <iostream>
#include <fstream>
#include <vector>
struct Record {
int id;
char name[20];
double score;
};
int main() {
std::vector<Record> records = {
{1, "Alice", 95.5},
{2, "Bob", 87.3},
{3, "Charlie", 91.8}
};
std::ofstream outFile("records.bin", std::ios::binary);
if (outFile.is_open()) {
for (const auto& record : records) {
outFile.write(reinterpret_cast<const char*>(&record), sizeof(Record));
}
outFile.close();
std::cout << "Successfully wrote binary data to the file." << std::endl;
} else {
std::cerr << "Unable to open file" << std::endl;
}
return 0;
}