c++怎么用for输入多组数据。

c++怎么用for输入多组数据。举个例子,利用for,在控制台窗口完成输入30个学生的学号,名字,和5门课程成绩。

/*已测试,可参考修改,也复制粘贴,希望能帮到你!*/
#include <iostream>
#include <string>

using namespace std;

struct data  //储存学生信用,用结构最合适;
{    
    string name;  //学生姓名;
    unsigned int stu_num;  //学号;
    float score[5];  //5门课的成绩;
};

int main()
{
    data student[30] {};
    
    for(int i {}; i < 30; ++i)  //输入30个学生的信息;
    {
        cout << "请输入第 " << i + 1 << " 位学生的姓名:";
        getline(cin, student[i].name);
        cout << "请输入" << student[i].name << "的学号:";
        cin >> student[i].stu_num;
        cout << "请输入" << student[i].name << "的五门成绩\n";
        
        for(int j {}; j < 5; ++j)
        {
            cout << "第 " << j + 1 << " 门:";
            cin >> student[i].score[j]; 
        }
        
        cin.get();
        cout << endl; 
    }
    
    cout << "\n\n\n输入信息如下:\n";
     
    for(int i {}; i < 30; ++i)  //输出30个学生的信息;
    {
        cout << "姓名:" << student[i].name << "\n学号:" << student[i].stu_num << "\n五门科目成绩" << '\n';
        
        for(int j {}; j < 5; ++j)
            cout << "科目" << j + 1 << "成绩(分):" << student[i].score[j] << '\n';
            
        cout << endl; 
    }
    
    return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答