![]() |
#2
zhshh2017-09-17 09:56
|

#include <iostream>
#include<string>
using namespace std;
struct student {
long number;
string name;
char sex;
int score;
};
main()
{
int i;
student stu[50];
student* p;
//for (i=1; i<=3; i++) {
// cin>>stu[i].name;
// stu[i].number=i;
// cin>>stu[i].score;
//}
//for (i=1; i<=3; i++) {
// cout.width(20);
// cout<<stu[i].name;
// cout.width(10);
// cout<<stu[i].score;
// cout<<endl;
//}
p=&stu[1];
for (i=1; 1<=3; i++) {
p+=1;
cin>>p->name;
p->number=i+3;
cin>>p->score;
cout<<i;
}
for (i=1; i<=3; i++) {
cout.width(20);
cout<<stu[i].name;
cout.width(10);
cout<<stu[i].score;
cout<<endl;
}
return 0;
}
#include<string>
using namespace std;
struct student {
long number;
string name;
char sex;
int score;
};
main()
{
int i;
student stu[50];
student* p;
//for (i=1; i<=3; i++) {
// cin>>stu[i].name;
// stu[i].number=i;
// cin>>stu[i].score;
//}
//for (i=1; i<=3; i++) {
// cout.width(20);
// cout<<stu[i].name;
// cout.width(10);
// cout<<stu[i].score;
// cout<<endl;
//}
p=&stu[1];
for (i=1; 1<=3; i++) {
p+=1;
cin>>p->name;
p->number=i+3;
cin>>p->score;
cout<<i;
}
for (i=1; i<=3; i++) {
cout.width(20);
cout<<stu[i].name;
cout.width(10);
cout<<stu[i].score;
cout<<endl;
}
return 0;
}
上面第三个for(没有注释的第一个for)运行时i从1一直到了N,不在i<=3还是运行
只有本站会员才能查看附件,请 登录
如图开始注释掉的句子是最开始可以用的,因为正在学c++,尽可能的用复杂些,然后就出错了。。。