| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 575 人关注过本帖
标题:c++结构体怎么弄?
只看楼主 加入收藏
aqwszddd
Rank: 1
等 级:新手上路
帖 子:23
专家分:9
注 册:2014-1-15
结帖率:71.43%
收藏
已结贴  问题点数:20 回复次数:4 
c++结构体怎么弄?
#include <iostream>
#include <string>
using namespace std;
struct DATE
    {
  int year;
  int month;
  int day;
  };
struct STUDENT
    {
  int num;
  string name;
    DATE birthday;
    float score;
    }st;
void input(STUDENT &st)
{
    int i;
    cin>>"请输入第">>i>>"位学生">>endl>>"请输入学号">>i>>endl>>"请输入学生姓名">>st.name[i]>>endl;
    cin>>"请输入学生出生日期">>st.birthday.year>>st.birthday.month>>st.birthday.day>>endl;
    cin>>"请输入学生成绩">>st.score>>endl;
    }
void print(STUDENT *st)
{
    int i;
    cout<<"请输入第"<<i<<"位学生"<<endl<<"请输入学号"<<i<<endl<<"请输入学生姓名"<<st.name[i]<<endl;
    cout<<"请输入学生出生日期"<<st.birthday.year<<st.birthday.month<<st.birthday.day<<endl;
    cout<<"请输入学生成绩"<<st.score<<endl;
    }
int main()
{
    int i;
    STUDENT stu[2];
    for(i=0;i<2;i++)
        input(stu[i]);
    for(i=0;i<2;i++)
        print(stu[i]);
    return 0;
}
有错误。
&st与*st怎么弄?
搜索更多相关主题的帖子: 出生日期 include 姓名 结构体 
2014-03-30 20:52
天使梦魔
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:37
帖 子:564
专家分:2754
注 册:2007-8-29
收藏
得分:20 
cin>>"请输入第">>i
..............


.是成员指针
->是成员引用

如果参数是&st
那么成员使用指针,就是 st.num
如果参数是*st
那么成员使用引用,就是 st->num
作用都是导出符号,不然会出现指针的指针
收到的鲜花
  • aqwszddd2014-03-31 10:57 送鲜花  3朵  
2014-03-30 21:54
aqwszddd
Rank: 1
等 级:新手上路
帖 子:23
专家分:9
注 册:2014-1-15
收藏
得分:0 
亲,麻烦你在说清楚一下好吗?在main函数中怎么用?                                        unknown character '0xa1‘
D:\Program Files\Microsoft Visual Studio\MyProjects\Te.cpp(28) : error C2227: left of '->year' must point to class/struct/union
D:\Program Files\Microsoft Visual Studio\MyProjects\Te.cpp(28) : error C2819: type 'DATE' does not have an overloaded member 'operator ->
怎么回事?
2014-03-31 06:57
aqwszddd
Rank: 1
等 级:新手上路
帖 子:23
专家分:9
注 册:2014-1-15
收藏
得分:0 
#include <iostream>
#include <string>
using namespace std;
struct DATE
    {
    int month;
    int day;
    int year;
    };
struct STUDENT
    {
    int num;
    char name[20];
    DATE birthday;
    float score;
    }st;
void input(STUDENT &st)
{
    static int i=1;
    cout<<"请输入第"<<i<<"名学生信息:"<<endl;
    cout<<"请输入学号:"<<i<<endl;
    cout<<"请输入学生姓名:";
    cin>>st.name;
    cout<<"请输入学生出生日期:";
    cin>>st.birthday.year>>st.birthday.month>>st.birthday.day;
    cout<<"请输入学生成绩:";
    cin>>st.score;
    i++;
    }
void print(STUDENT *st)
{
    static int i=1;
    cout<<"请输出第"<<i<<"名学生信息"<<endl;
    cout<<"请输出学号"<<i<<endl;
    cout<<"请输出学生姓名"<<st->name<<endl;
    cout<<"请输出学生出生日期"<<st->birthday.year<<'\t'<<st->birthday.month<<'\t'<<st->birthday.day<<endl;
    cout<<"请输出学生成绩:"<<st->score<<endl;
    i++;
    }
int main()
{   
    int i;
    STUDENT stu[2];
    for(i=0;i<2;i++)
        input(stu[i]);
    for(i=10;i<2;i++)
        print(&stu[i]);
    return 0;
}
已解决谢谢
2014-03-31 10:47
QQ1397156393
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-4-3
收藏
得分:0 
你们学到哪里了啊。。。。这样的程序我目前还写不出来。、、
2014-04-03 11:08
快速回复:c++结构体怎么弄?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016064 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved