64,652
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct Student_info //学生的成绩
{
string name;
double midterm,final;
vector<double> homework;
};
istream& read_hw(istream& in,vector<double>& hw)
{
if (in)
{
hw.clear();
double x;
while (in>>x)
{
hw.push_back(x);
}
in.clear();
}
return in;
}
istream& read(istream& is,Student_info& s)
{
//cout<<"输入姓名,期中,期末:";
is>>s.name>>s.midterm>>s.final;
//cout<<"输入家庭作业成绩:";
read_hw(is,s.homework); //读取家庭作业
return is;
}
int main()
{
vector<Student_info> students;
Student_info record;
string::size_type maxlen=0;
while (read(cin,record))
{
maxlen=max(maxlen,record.name.size());
students.push_back(record);
}
//后面输出省略
return 0;
}
istream& read_hw(istream& in,vector<double>& hw)
{
if (in)
{
hw.clear();
double x;
while (in>>x)
{
hw.push_back(x);
}
in.clear();
in.sync();
}
return in;
}