prog2.cpp
来自「C++语言程序设计题典」· C++ 代码 · 共 23 行
CPP
23 行
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
void main()
{
struct student
{
char name[10];
int no;
double score;
} stud[]={"Ma",9902,76,"Li",9906,85.6,"Zheng",9909,
82.5,"Chen",9918,88.6};
fstream file1;
student one;
file1.open("stud.dat",ios::in|ios::out|ios::binary);
for (int i=0;i<4;i++)
file1.write((char*)&stud[i],sizeof(student));
file1.seekp(sizeof(student)*2);
file1.read((char*)&one,sizeof(student));
cout << one.no << " " << one.name << " " << one.score << endl;
file1.close();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?