主题:[原创]简单的一个程序,请高手帮忙修正!
#include<iostream.h>
#include<string>
using namespace std;
int main(void)
{int i,j;
struct stu{
string id;
string name;
int score[3];
float average;
}c_pp[10];
for(i=0;i<5;i++)
{
int sum=0;
cout<<"请输入第"<<i+1<<"个学生信息:"<<endl;
cin>>c_pp[i].id;
cin>>c_pp[i].name;
cin>>c_pp[i].score[0];
cin>>c_pp[i].score[1];
cin>>c_pp[i].score[2];
for(j=0;j<3;j++)
sum+=c_pp[i].score[j];
c_pp[i].average=sum/3.0;
cout<<endl<<"c_pp["<<i+1<<"].average="<<c_pp[i].average<<endl;
}
return 0;
}
程序想实现功能,输入学生的信息,输出平均成绩。
但是程序执行不了,编译时错误提示:
:\program files\microsoft visual studio\myprojects\test\test.cpp(18) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
(or there is no acceptable conversion)
c:\program files\microsoft visual studio\myprojects\test\test.cpp(19) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
(or there is no acceptable conversion)
Error executing cl.exe.
test.obj - 2 error(s), 0 warning(s)
请高手帮忙看看!
#include<string>
using namespace std;
int main(void)
{int i,j;
struct stu{
string id;
string name;
int score[3];
float average;
}c_pp[10];
for(i=0;i<5;i++)
{
int sum=0;
cout<<"请输入第"<<i+1<<"个学生信息:"<<endl;
cin>>c_pp[i].id;
cin>>c_pp[i].name;
cin>>c_pp[i].score[0];
cin>>c_pp[i].score[1];
cin>>c_pp[i].score[2];
for(j=0;j<3;j++)
sum+=c_pp[i].score[j];
c_pp[i].average=sum/3.0;
cout<<endl<<"c_pp["<<i+1<<"].average="<<c_pp[i].average<<endl;
}
return 0;
}
程序想实现功能,输入学生的信息,输出平均成绩。
但是程序执行不了,编译时错误提示:
:\program files\microsoft visual studio\myprojects\test\test.cpp(18) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
(or there is no acceptable conversion)
c:\program files\microsoft visual studio\myprojects\test\test.cpp(19) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
(or there is no acceptable conversion)
Error executing cl.exe.
test.obj - 2 error(s), 0 warning(s)
请高手帮忙看看!