为什么当输出结果时,student2.score前面会有多余的换行

代码

#include<iostream>

using namespace std;

int main()
{
    struct Student 
    {
        int num;
        char name[20];
        double score;
    }student1,student2;
    
    cin>>student1.num>>student1.score;
    fgets(student1.name,20,stdin);
    
    cin>>student2.num>>student2.score;
    fgets(student2.name,20,stdin);
    
    if(student1.score>student2.score) cout<<student1.num<<student1.name<<student1.score<<endl;
    else  cout<<student2.num<<student2.name<<student2.score<<endl;
    
    return 0;
}

输入
10101 89 wang
10103 90 lin
输出结果
10103 lin
90

“但是需要注意的是,如果输入的字符串长度没有超过 n–1,那么系统会将最后输入的换行符 '\n' 保存进来,保存的位置是紧跟输入的字符,然后剩余的空间都用 '\0' 填充。所以此时输出该字符串时 printf 中就不需要加换行符 '\n' 了,因为字符串中已经有了。”------------from c.biancheng.net/view/235.html