实验七

Posted nicholastwo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验七相关的知识,希望对你有一定的参考价值。

1、

#include<iostream>
#include<string>
#include<fstream> 
#include<ctime>
const int N=83;
using namespace std;
    struct student{
        string num;
       string id,name,cl;
    };
    int main()
    {
        int i;
        student stu[N];
        ifstream in("list.txt");
        if(!in)
        {
            cout<<"fail to open"<<endl;
            return 1;
        }
        for(int i=0;i<=N;i++)
        {
            in>>stu[i].num>>stu[i].id>>stu[i].name>>stu[i].cl;
        }
        in.close();
        ofstream out("roll.txt");
        for(i=0;i<5;i++)
        {
            int a=rand()%N+1;
            srand(time(nullptr));
            cout<<stu[a].num<<" "<<stu[a].id<<" "<<stu[a].name<<" "<<stu[a].cl<<endl;
        out<<stu[a].num<<" "<<stu[a].id<<" "<<stu[a].name<<" "<<stu[a].cl<<endl;
            
        }
        out.close();
        return 0;
    }

我jio的我写的没什么问题,可就是运行不出来,可能会我电脑路径或者系统的问题,因为我发现我的list都不是.txt形式,就很气
明天去问问老师好了


以上是关于实验七的主要内容,如果未能解决你的问题,请参考以下文章