64,282
社区成员
发帖
与我相关
我的任务
分享
typedef struct o
{
string tecName;
string tecInfo;
int qw;
int iwork;
} stec;
int main(void)
{
const char filename[] = "mytext.txt";
ofstream o_file;
cout << "几位老师?" << endl;
int num=0,i=0;
cin >> num;
stec *tec = new stec[num];
o_file.open(filename);
for(i=0;i<num;i++)
{
cout << "第 " << i+1 << " 位都是:姓名,科目,期望值,工作量" << endl;
cin >> tec[i].tecName;
cin >> tec[i].tecInfo;
cin >> tec[i].qw;
cin >> tec[i].iwork;
o_file << tec[i].tecName << endl;
o_file << tec[i].tecInfo << endl;
o_file << tec[i].qw << endl;
o_file << tec[i].iwork << endl;
}
o_file.close();
srand(time(NULL));
int iRnd = rand()%num;
ifstream i_file;
i_file.open(filename);
string out_text;
cout << "iRnd=" << iRnd << endl;
for(i=0;i<num*4;i++)
{
i_file >> out_text;
if(i>=iRnd*4 && i<iRnd*4+4)
{
cout << out_text << endl;
}
if(i>iRnd*4+4)
{
break;
}
}
i_file.close();
return 0;
}