C++程序错误求助
#include<iostream.h>structstudent{charname[20];charnumber[20];intscore1,score2,score3...
#include<iostream.h>
struct student
{
char name[20];
char number[20];
int score1,score2,score3;
}stu[11];
void main()
{
int i;
student stu[11];
for(i=1;i<=10;i++)
{
cout<<"请输入第"<<i<<"个学生的name,number,score1,score2,score3:"<<endl;
cin>>stu[i-1].name<<stu[i-1].number<<stu[i-1].score1<<stu[i-1].score2<<stu[i-1].score3<<endl;
}
int j;
for(i=1;i<=9;i++)
{
for(j=i+1;j<=10;j++)
{
if('stu[i-1].name[0]'>'stu[j-1].name[0]')
{
stu[10]=stu[i-1];
stu[i-1]=stu[j-1];
stu[j-1]=stu[10];
}
}
}
for(i=1;i<=10;i++)
{
cout<<stu[i-1].name<<' '<<stu[i-1].number<<' '<<stu[i-1].score1<<' '<<stu[i-1].score2<<' '<<stu[i-1].score3<<endl;
}
}
错误信息是
Compiling...
as.cpp
F:\VC\my work\as.cpp(15) : error C2676: binary '<<' : 'class istream' does not define this operator or a conversion to a type acceptable to the predefined operator
F:\VC\my work\as.cpp(22) : error C2015: too many characters in constant
F:\VC\my work\as.cpp(22) : error C2015: too many characters in constant
执行 cl.exe 时出错.
as.obj - 1 error(s), 0 warning(s) 展开
struct student
{
char name[20];
char number[20];
int score1,score2,score3;
}stu[11];
void main()
{
int i;
student stu[11];
for(i=1;i<=10;i++)
{
cout<<"请输入第"<<i<<"个学生的name,number,score1,score2,score3:"<<endl;
cin>>stu[i-1].name<<stu[i-1].number<<stu[i-1].score1<<stu[i-1].score2<<stu[i-1].score3<<endl;
}
int j;
for(i=1;i<=9;i++)
{
for(j=i+1;j<=10;j++)
{
if('stu[i-1].name[0]'>'stu[j-1].name[0]')
{
stu[10]=stu[i-1];
stu[i-1]=stu[j-1];
stu[j-1]=stu[10];
}
}
}
for(i=1;i<=10;i++)
{
cout<<stu[i-1].name<<' '<<stu[i-1].number<<' '<<stu[i-1].score1<<' '<<stu[i-1].score2<<' '<<stu[i-1].score3<<endl;
}
}
错误信息是
Compiling...
as.cpp
F:\VC\my work\as.cpp(15) : error C2676: binary '<<' : 'class istream' does not define this operator or a conversion to a type acceptable to the predefined operator
F:\VC\my work\as.cpp(22) : error C2015: too many characters in constant
F:\VC\my work\as.cpp(22) : error C2015: too many characters in constant
执行 cl.exe 时出错.
as.obj - 1 error(s), 0 warning(s) 展开
3个回答
展开全部
#include <iostream>
using namespace std;
struct student
{
char name[20];
char number[20];
int score1,score2,score3;
}; //这里删了
int main()
{
int i;
student stu[11];
for(i=1;i<=10;i++)
{
cout<<"请输入第"<<i<<"个学生的name,number,score1,score2,score3:"<<endl;
cin>>stu[i-1].name>>stu[i-1].number>>stu[i-1].score1>>stu[i-1].score2>>stu[i-1].score3; //这里的<<改为>>
}
int j;
for(i=1;i<=9;i++)
{
for(j=i+1;j<=10;j++)
{
if(stu[i-1].name[0]>stu[j-1].name[0])//这里把单引号去了,stu[i-1].name[0]本身就代表是一个字符
{
stu[10]=stu[i-1];
stu[i-1]=stu[j-1];
stu[j-1]=stu[10];
}
}
}
for(i=1;i<=10;i++)
{
cout<<stu[i-1].name<<' '<<stu[i-1].number<<' '<<stu[i-1].score1<<' '<<stu[i-1].score2<<' '<<stu[i-1].score3<<endl;
}
return 0;
}
using namespace std;
struct student
{
char name[20];
char number[20];
int score1,score2,score3;
}; //这里删了
int main()
{
int i;
student stu[11];
for(i=1;i<=10;i++)
{
cout<<"请输入第"<<i<<"个学生的name,number,score1,score2,score3:"<<endl;
cin>>stu[i-1].name>>stu[i-1].number>>stu[i-1].score1>>stu[i-1].score2>>stu[i-1].score3; //这里的<<改为>>
}
int j;
for(i=1;i<=9;i++)
{
for(j=i+1;j<=10;j++)
{
if(stu[i-1].name[0]>stu[j-1].name[0])//这里把单引号去了,stu[i-1].name[0]本身就代表是一个字符
{
stu[10]=stu[i-1];
stu[i-1]=stu[j-1];
stu[j-1]=stu[10];
}
}
}
for(i=1;i<=10;i++)
{
cout<<stu[i-1].name<<' '<<stu[i-1].number<<' '<<stu[i-1].score1<<' '<<stu[i-1].score2<<' '<<stu[i-1].score3<<endl;
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询