11_8.cpp
来自「C++多个例题的源代码及分析.有兴趣的可以」· C++ 代码 · 共 30 行
CPP
30 行
//11_8.cpp
#include<iostream>
#include <fstream>
#include<cstring>
using namespace std;
void 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 + -
显示快捷键?