| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 564 人关注过本帖
标题:请各位大神帮我寻找一下这个C程序的错误!
取消只看楼主 加入收藏
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
结帖率:90.24%
收藏
已结贴  问题点数:20 回复次数:2 
请各位大神帮我寻找一下这个C程序的错误!
#include<iostream>
#include<string>
using namespace std;

struct person
{
    string name;
    int num;
    char sex;
    char job;
    union P
    {
        float grade;
        string prof;
    }kind;

};

int main()
{
    int i;
    person stu[3];
    cout<<"请输入职员信息:"<<endl;
    for(i=0;i<3;i++)
    {
        cin>>stu[i].name>>stu[i].num>>stu[i].sex>>stu[i].job;
        if(stu[i].job=='t')
            cin>>stu[i].kind.prof;
        else
            cin>>stu[i].kind.grade;
    }
    cout<<"列表内学生信息为:"<<endl;
    for(i=0;i<3;i++)
    {
        if(stu[i].job=='t')
            cout<<stu[i].name<<'_'<<stu[i].num<<'_'<<stu[i].sex<<'_'<<stu[i].job<<'_'<<stu[i].kind.prof<<endl;
        else
            cout<<stu[i].name<<'_'<<stu[i].num<<'_'<<stu[i].sex<<'_'<<stu[i].job<<'_'<<stu[i].kind.grade<<endl;
    }

}
2015-09-11 21:32
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
收藏
得分:0 
回复 2楼 诸葛欧阳
编译信息大概是这样哒:

Compiling...
Cpp1.cpp
C:\Users\123\Desktop\practice 5\Cpp1.cpp(14) : error C2621: union 'P' : member 'prof' has copy constructor
C:\Users\123\Desktop\practice 5\Cpp1.cpp(28) : error C2039: 'prof' : is not a member of 'P'
        C:\Users\123\Desktop\practice 5\Cpp1.cpp(12) : see declaration of 'P'
C:\Users\123\Desktop\practice 5\Cpp1.cpp(36) : error C2039: 'prof' : is not a member of 'P'
        C:\Users\123\Desktop\practice 5\Cpp1.cpp(12) : see declaration of 'P'
C:\Users\123\Desktop\practice 5\Cpp1.cpp(41) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

Cpp1.exe - 1 error(s), 0 warning(s)

既然还有不甘心
就还没到放弃的时候~
2015-09-20 16:34
S140131022
Rank: 2
来 自:重庆邮电大学
等 级:论坛游民
帖 子:205
专家分:35
注 册:2014-10-9
收藏
得分:0 
回复 3楼 rjsp
我给union类型改成struct类型 编译就通过啦!

是不是因为编译器的问题?

既然还有不甘心
就还没到放弃的时候~
2015-09-20 16:38
快速回复:请各位大神帮我寻找一下这个C程序的错误!
数据加载中...
 
   



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

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