如果我是一个编程很厉害的人就好了 2022-11-28 23:40 采纳率: 63.6%
浏览 325
已结题

怎么将键盘输入的数据输入到结构体中c++

不会用所学的知识,把键盘中的数据输入到结构体中

#include <iostream>
using namespace std;
struct student 
{
    int no;
    char name [6];
    int age;
    student *next;
};
int main()
{
int x;
cin>>x;
for(int si=0;si<x;si++)
{
    struct student si;
    cin>>si.no;
    cin>>si.name;
    cin>>si.age;
}
cout<<s3.no;
    return 0;
}

以上是简单测试了一下,程序报错,是不是要用什么函数啊
求解,我会的的知识可能不是太多,请多多指教,感谢!

  • 写回答

2条回答 默认 最新

  • 时语-shine 2022-11-28 23:56
    关注
    
    #include <iostream>
    using namespace std;
    struct student
    {
        int no;
        char name[6];
        int age;
        student* next;
    };
    int main()
    {
            struct student si;
            cin >> si.no;
            cin >> si.name;
            cin >> si.age;
        cout << si.no;
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月10日
  • 已采纳回答 12月2日
  • 修改了问题 11月28日
  • 创建了问题 11月28日