```cpp #include <iostream> #include <fstream> #include <string> using namespace std; class bindata { private: int data[20]; public: bindata(const string filename = "") { if (filename != "") { ifstream file(filename, ios::binary); if (file) { for (int i = 0; i < 20; i++) { if (!file.read(reinterpret_cast<char*>(&data[i]), sizeof(int))) { break; } } file.close(); } } } void savedata(const string s) { ofstream file(s, ios::binary); if (file) { for (int i = 0; i < 20; i++) { file.write(reinterpret_cast<char*>(&data[i]), sizeof(int)); } file.close(); } } friend ostream& operator<<(ostream& os, const bindata& bd) { for (int i = 0; i < 20; i++) { os << bd.data[i] << " "; } return os; } }; int main() { bindata bd("data.bin"); cout << bd << endl; bd.savedata("output.bin"); return 0; } ``` [2024-06-01 15:35:51 | AI写代码神器 | 754点数解答]