XiaoHui.net 笑汇程序员论坛首页
工作并快乐着,职业并休闲着
寻梦的岁月从不言辛苦几许,
不问收获几多……
» 游客:  申请新用户 | 登录 | 会员 | 统计 | 帮助 » XiaoHui.Net 笑汇程序员论坛 | 纯文字版 | 全站索引 | XiaoHui.com


[其他] 照书上敲的,自己也看了,还是不明白怎么错了。

RSS 订阅当前论坛  

上一主题 下一主题
     

标题: [其他] 照书上敲的,自己也看了,还是不明白怎么错了。  
 
keith
传说中的水手
Rank: 5Rank: 5



UID 21419
精华 0
积分 68
帖子 68
阅读权限 1
注册 2006-4-25
状态 离线
照书上敲的,自己也看了,还是不明白怎么错了。

如下:

#include <iostream.h>
#include <iomanip.h>
struct student
{
        char id[10];
        char name[20];
        char sex;
        int age;
        char department[30];
        float score;
};
void main()
{
        student student1={"05030100","MeiHuan","M",20,"Computer",95},
        student2={"05030101","MsiHfdn","M",21,"Physics",98};
        float ave;
        cout<<student1.id<<" "<<student1.name<<" "<<student1.sex<<" "<<student1.age<<" "<<student1.department<<" "<<student1.score<<endl;
        cout<<student2.id<<" "<<student2.name<<" "<<student2.sex<<" "<<student2.age<<" "<<student2.department<<" "<<student2.score<<endl;
        ave=(student1.score+student2.score)/2;
        cout<<"ave="<<ave<<endl;
        cout<<"sizeofstudent1="<<sizeof(student1)<<endl;
}


--------------------Configuration: examplech217 - Win32 Debug--------------------
Compiling...
examplech217.cpp
I:\file\vc\examplech217.cpp(15) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'char'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
I:\file\vc\examplech217.cpp(15) : error C2440: 'initializing' : cannot convert from 'char [9]' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
I:\file\vc\examplech217.cpp(16) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'char'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
I:\file\vc\examplech217.cpp(16) : error C2440: 'initializing' : cannot convert from 'char [8]' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.

examplech217.obj - 4 error(s), 0 warning(s)
不知道怎么错了。
不懂上面说什么。
谢谢指点。
2006-7-28 16:31#1
查看资料  Blog  发短消息  顶部
 
jiaoyj
小水手
Rank: 1



UID 22297
精华 0
积分 17
帖子 17
阅读权限 10
注册 2006-7-6
状态 离线
你的 sex是一个char, 给值得时候不能用 "m"这个不是成了字符串了吗?要用'm'
2006-7-31 23:43#2
查看资料  Blog  发短消息  QQ  顶部
 
keith
传说中的水手
Rank: 5Rank: 5



UID 21419
精华 0
积分 68
帖子 68
阅读权限 1
注册 2006-4-25
状态 离线
谢谢jiaoyj
的确如此
2006-8-1 13:04#3
查看资料  Blog  发短消息  顶部
 
delphiroot
小水手
Rank: 1



UID 30476
精华 0
积分 9
帖子 9
阅读权限 10
注册 2007-8-14
状态 离线
struct student
{
        char id[10];
        char name[20];
        char sex;
        int age;
        char department[30];
        float score;
} student1, student2;
2007-8-17 13:29#4
查看资料  Blog  发短消息  顶部
 
kzzk
传说中的水手
Rank: 5Rank: 5



UID 10883
精华 0
积分 174
帖子 174
阅读权限 1
注册 2003-6-30
状态 离线
哦  明白了

123456
2007-8-20 00:07#5
查看资料  访问主页  Blog  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题  


 


所有时间为 GMT+8, 现在时间是 2008-11-21 14:47 Powered by Discuz! 4.1.0 清除 Cookies - XiaoHui.Net 笑汇程序员论坛 - Archiver