c++的一道题显示错误为 error C2676
#include<iostream>#include<string>usingnamespacestd;structstudent{intnum;stringname;f...
#include<iostream>
#include<string>
using namespace std;
struct student
{
int num;
string name;
float score[3];
}stu[5];
void input(student &stu)
{
int i,k;
for (i=0;i<5;i++)
{
cin>>stu[i].num>>stu[i].name;
for(k=0;k<3;k++)
cin>>stu[i].score[k];
}}
void print(student stu)
{
int k;
cout<<stu.num<<" "<<stu.name<<" ";
for(k=0;k<3;k++)
{cout<<stu.score[k]<<" ";}
cout<<endl;
}
int main()
{
int i;
for (i=0;i<5;i++)
{
input(stu[i]);
print(stu[i]);}
return 0;
}
错误显示为:
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(15) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(15) : error C2228: left of '.num' must have class/struct/union type
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(15) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(15) : error C2228: left of '.name' must have class/struct/union type
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(17) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(17) : error C2228: left of '.score' must have class/struct/union type
执行 cl.exe 时出错. 展开
#include<string>
using namespace std;
struct student
{
int num;
string name;
float score[3];
}stu[5];
void input(student &stu)
{
int i,k;
for (i=0;i<5;i++)
{
cin>>stu[i].num>>stu[i].name;
for(k=0;k<3;k++)
cin>>stu[i].score[k];
}}
void print(student stu)
{
int k;
cout<<stu.num<<" "<<stu.name<<" ";
for(k=0;k<3;k++)
{cout<<stu.score[k]<<" ";}
cout<<endl;
}
int main()
{
int i;
for (i=0;i<5;i++)
{
input(stu[i]);
print(stu[i]);}
return 0;
}
错误显示为:
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(15) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(15) : error C2228: left of '.num' must have class/struct/union type
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(15) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(15) : error C2228: left of '.name' must have class/struct/union type
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(17) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\SAMSUNG\Desktop\文件夹\资料\应用程序\3.cpp(17) : error C2228: left of '.score' must have class/struct/union type
执行 cl.exe 时出错. 展开
3个回答
展开全部
#include<iostream>
#include<string>
using namespace std;
typedef struct student
{
int num;
string name;
float score[3];
}stu;
void input(student &stu)
{
cin >> stu.num >> stu.name;
for (int k = 0; k < 3; k++)
cin >> stu.score[k];
}
void print(student stu)
{
cout << stu.num << " " << stu.name << " ";
for (int k = 0; k < 3; k++)
{
cout << stu.score[k] << " ";
}
cout << endl;
}
int main()
{
stu s[5];
int i;
for (i = 0; i < 5; i++)
{
input(s[i]);
print(s[i]);
}
return 0;
}
#include<string>
using namespace std;
typedef struct student
{
int num;
string name;
float score[3];
}stu;
void input(student &stu)
{
cin >> stu.num >> stu.name;
for (int k = 0; k < 3; k++)
cin >> stu.score[k];
}
void print(student stu)
{
cout << stu.num << " " << stu.name << " ";
for (int k = 0; k < 3; k++)
{
cout << stu.score[k] << " ";
}
cout << endl;
}
int main()
{
stu s[5];
int i;
for (i = 0; i < 5; i++)
{
input(s[i]);
print(s[i]);
}
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
void input(student &stu)
{
int i,k;
cin>>stu.num>>stu.name;
for(k=0;k<3;k++)
{
cin>>stu.score[k];
}
}
{
int i,k;
cin>>stu.num>>stu.name;
for(k=0;k<3;k++)
{
cin>>stu.score[k];
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
编译器错误 C2676
错误消息:
二元“operator”:“type”不定义此运算符或到预定义运算符可接收的类型的转换
若要使用该运算符,必须针对指定类型将其重载,或者定义一个到某个类型(该运算符已针对此类型进行了定义)的转换。
更多的编译器错误查询:
http://msdn.microsoft.com/zh-cn/library/sah8k6f4.aspx
错误消息:
二元“operator”:“type”不定义此运算符或到预定义运算符可接收的类型的转换
若要使用该运算符,必须针对指定类型将其重载,或者定义一个到某个类型(该运算符已针对此类型进行了定义)的转换。
更多的编译器错误查询:
http://msdn.microsoft.com/zh-cn/library/sah8k6f4.aspx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询