⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 11-4-3-2.cpp

📁 学习c++的ppt
💻 CPP
字号:
#include <fstream.h>
struct  person  {
     char  name[20];
     int  age;
     double  score;
};
struct  person people[3] = {"Liu Hua",   23,  78,
                            "Wang Yu", 24, 85.7,
                            "Li San", 22, 98};
const  Plen = sizeof(struct person);
void main()
{    fstream  infile,  outfile;
     outfile.open("test.txt",  ios::out|ios::binary);
     //  不成,退出     
     for(int i = 0; i < 3; i ++)
          outfile.write((char *)&people[i], Plen);
     outfile.close();
     infile.open("test.txt",  ios::in|ios::binary);
     //  不成,退出
	 cout << "Len: " << Plen << endl;
     struct person buf;
     for(i = 0; i < 3; i ++)   {
           infile.read((char *)&buf, Plen);
           cout << buf.name << '\t' << buf.age << '\t' <<
                          buf.score << endl;
     }
     infile.close();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -