11_8.cpp
来自「清华大学郑莉《C++语言程序设计》课件、C++教材源代码、实验参考程序全集」· C++ 代码 · 共 30 行
CPP
30 行
//11_8.cpp
#include<iostream>
#include <fstream>
#include<cstring>
using namespace std;
int main()
{
struct
{
double salary;
char name[23];
} employee1, employee2;
employee1.salary=8000;
strcpy(employee1.name, "L Zheng");
ofstream outfile("payroll",ios_base::binary);
outfile.write((char *) &employee1,sizeof(employee1));
outfile.close();
ifstream is("payroll",ios_base::binary);
if (is)
{
is.read((char *) &employee2,sizeof(employee2));
cout << employee2.name << ' ' << employee2.salary << endl;
}
else
{
cout << "ERROR: Cannot open file 'payroll'." << endl;
}
is.close();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?