二进制“>>”: 没有找到接受“int [5]”类型的右操作数的运算符(或没有可接受的转换)

Topazpeach 2016-05-02 08:03:15
#include<iostream>
using namespace std;
struct Student
{
int score[5];
char name[20];
};
int main()
{
Student st[5];
for(int i=0;i<5;i++)
cin>>st[i].name>>st[i].score;
for(int i=0;i<5;i++)
{
for(int j=i+1;j<5;j++)
{
if(st[j].score>st[i].score)
{
Student temp=st[i];
st[i]=st[j];
st[j]=temp;
}
}
}
for(int i=0;i<5;i++)
{
cout<<st[i].name<<st[i].score;}
return 0;
}

第12行总是显示标题所示错误……
...全文
349 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
小灸舞 2016-05-02
  • 打赏
  • 举报
回复
目测权限问题
Topazpeach 2016-05-02
  • 打赏
  • 举报
回复
引用 3 楼 qq423399099 的回复:
struct Student里int score[5];改为int score;

#include<iostream>
using namespace std;
struct Student
{
int score;
char name[20];
};
int main()
{
Student st[5];
for(int i=0;i<5;i++)
cin>>st[i].name>>st[i].score;
for(int i=0;i<5;i++)
{
for(int j=i+1;j<5;j++)
{
if(st[j].score>st[i].score)
{
Student temp=st[i];
st[i]=st[j];
st[j]=temp;
}
}
}
for(int i=0;i<5;i++)
{
cout<<st[i].name<<st[i].score;}
return 0;
}

好的非常感谢~这个问题解决了……然后还有一个问题……我尝试用老师说的从外部输入输出重定向,为什么出现了这样的问题呢?
小灸舞 2016-05-02
  • 打赏
  • 举报
回复
struct Student里int score[5];改为int score;

#include<iostream>
using namespace std;
struct Student
{
int score;
char name[20];
};
int main()
{
Student st[5];
for(int i=0;i<5;i++)
cin>>st[i].name>>st[i].score;
for(int i=0;i<5;i++)
{
for(int j=i+1;j<5;j++)
{
if(st[j].score>st[i].score)
{
Student temp=st[i];
st[i]=st[j];
st[j]=temp;
}
}
}
for(int i=0;i<5;i++)
{
cout<<st[i].name<<st[i].score;}
return 0;
}
Topazpeach 2016-05-02
  • 打赏
  • 举报
回复
引用 1 楼 dustpg 的回复:
说得很清楚啊,没有 (int [5])类型的重载,哪个C++教材/教程说了能直接输入int数组,自己用个循环就行了
我知道没有这个的重载啊但是不知道什么意思啊。我不是用了for循环输入数组了吗?
dustpg 2016-05-02
  • 打赏
  • 举报
回复
说得很清楚啊,没有 (int [5])类型的重载,哪个C++教材/教程说了能直接输入int数组,自己用个循环就行了

64,691

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧