新微赢技术网

标题: 请找出错误 [打印本页]

作者: Оo水流影在.    时间: 2009-11-3 01:13
标题: 请找出错误
#include<iostream>
#include<string>
using namespace std;
struct Student{
int num;
string name;
char sex;
float score;
}
void main()
{

cout<<"num is"<<endl;
cout<<"name is"<<endl;
cout<<"sex is"<<endl;
cout<<"score is"<<endl;
Student stu;
Student *p=&stu;
cin>>(*p).num>>(*p).name>>(*p).sex>>(*p).score;
cout<<(*p).num<<" "<<(*P).name<<" "<<(*p).sex<<" "<<(*p).score<<endl;




#define NULL 0
#include<iostream>
using namespace std;
struct Student{

long num;
float score;
struct Student *next;
}
int main()
{
Student a,b,c,*head,*p;
a.num=31001;a.score=39.5;
b.num=31003;b.score=90;
c.num=31007;c.score=85;
head=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
do
{cout<<p->num<<" "<<p->score<<endl;}
p=p->next;
while
p!=NULL;
return 0;
}
}

我是菜鸟,请问这两则程序哪里错了
作者: 爱情海555    时间: 2009-11-3 01:13
#include <iostream>
#include <string.h>
using namespace std;
typedef struct Student{
int num;
string name;
char sex[12];
float score;
} Student;
int main()
{
Student stu;
cout<<"num is ";
cin>>stu.num;
cout<<"name is ";
char str[256];
cin>>str;
stu.name=str;
cout<<"sex is ";
cin>>stu.sex;
cout<<"score is ";
cin>>stu.score;
cout<<stu.num<<"\t"<<stu.name.c_str()<<"\t"<<stu.sex<<"\t"<<stu.score<<endl;
return 0;
}

#define NULL 0
#include<iostream>
using namespace std;
typedef struct Student
{
long num;
float score;
Student *next;
} Student;
int main()
{
Student a,b,c,*head,*p;
a.num=31001;a.score=39.5;
b.num=31003;b.score=90;
c.num=31007;c.score=85;
head=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
do
{
cout<<p->num<<" "<<p->score<<endl;
}
while ((p=p->next) != NULL);
return 0;
}




欢迎光临 新微赢技术网 (http://bbs.weiying.cn/) Powered by Discuz! X3.2