如下:
#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)
不知道怎么错了。
不懂上面说什么。
谢谢指点。