c++中如何从控制台一次读取多行数据?

比如 从控制台读取学生的成绩 格式为

学号 姓名 分数

我想要一次输入多个学生的数据, 多行 如何实现?

第1个回答  推荐于2016-08-07
struct student {
unsigned id; // 学号
char name[30];
double score;
};

#define N 5

struct student a[N];

void ReadData(struct student a[], int n) {
int i;
for(i = 0; i < n; ++i)
scanf("%d%s%lf",&a[i].in, &a[i].name, &a[i].score); // 收入时数据间用空格隔开
}追问

麻烦问一下 这个struct student a[N] 是不是就是student 的数组?? 前面为啥要加上 struct呀?

追答

是数组,类型是struct student。
加struct是C中的标准用法,在C++环境下可以不加。

本回答被提问者和网友采纳
第2个回答  2013-11-02
你好!!
你可以采用循环的方式来添加,for 或 while 都可以
相似回答