注册 登录
编程论坛 新人交流区

一个恶心的问题

diandianlian 发布于 2007-10-19 17:41, 902 次点击

# include<iostream.h>
# include<fstream.h>
# include<stdlib.h>
# include<string.h>

/* struct student
{
char name[30];
int number ,score;
};*/

void main()
{
/*char fileName[30];
cout<<"请输入文件名:"<<endl;
cin>>fileName;
fstream stu(fileName,ios::out|ios::in|ios::binary);
/*if(!stu)

{
cerr<<"文件打开失败!"<<endl;
abort();

}

student st;
student * ps=&st;
int counter1=0;
int counter2=0;
double total=0;
do
{

cout<<"请输入学号,姓名,分数\n?";

cin>>ps->number>>ps->name>>ps->score;
if(cin.get()==EOF)
break;
counter1++;

total+=ps->score;

stu.write((char*)ps,sizeof(student));
}while(1);

cout<<"平均分为:"<<total/counter1<<endl;
stu.seekg(0);
for(int i=0;i<counter1;i++)

{

stu.read((char*)ps,sizeof(student));
cout<<"学号为:"<<ps->number<<ends<<"姓名为:"<<ps->name<<ends<<"分数为:"<<ps->score<<endl;

}

char name2[30];
do
{
cout<<"请输入你想查询学生的姓名(noname结束):"<<endl;
cin>>name2;
/*if(!strcmp(name2,"noname"))
{
cout<<"退出查询!"<<endl;
return;
}
else
{
stu.seekg(0);

for(int i=0;i<counter1;i++)
{
stu.read((char*)ps,sizeof(student));
if(!(strcmp(ps->name,name2)))
{
cout<<"学号为:"<<ps->number<<ends<<"姓名为:"<<ps->name<<ends<<"分数为:"<<ps->score<<endl;
break;
}
else
counter2++;

}
if(counter2==counter1)
cout<<"没有你想查询的学生!"<<endl;
}*/
}while(1);




/* for(int pass=1;pass<counter1;pass++)
{

for(j=0;j<counter1-pass;j++)
{
if(pt[i]->score>pt[i+1]->scor)
{
temp=pt[i]->score;
pt[i]->score=pt[i+1]->scor;
pt[i+1]->scor=temp;
work=0;
}
}
if(work)break;

}
}
for(i=0;i<counter1;i++)
{
stu.seekg(0);
stu.read((char*)pt[i],sizeof(student));
}*/

}

各位帮忙看看这个程序的运行错误:运行到cin时不能输入。

26 回复
#2
稀饭老鼠2007-10-19 18:09

似乎很高深!不会

#3
jojo_fjl2007-10-19 18:12
......
#4
guobingyu2007-10-19 18:20
cin>>ps->number>>ps->name>>ps->score;
是他的问题吗???????
#5
yoapple2007-10-19 19:29

太多错误:
1 D:\Program Files\Dev\Dev-Cpp\include\c++\3.3.1\backward\iostream.h:31, from main.cpp In file included from D:/Program Files/Dev/Dev-Cpp/include/c++/3.3.1/backward/iostream.h:31, from main.cpp
1 D:\Program Files\Dev\Dev-Cpp\main.cpp from main.cpp
2 D:\Program Files\Dev\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
2 D:\Program Files\Dev\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
2 D:\Program Files\Dev\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
2 D:\Program Files\Dev\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
2 D:\Program Files\Dev\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
2 D:\Program Files\Dev\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
2 D:\Program Files\Dev\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.

#6
loveling2007-10-19 19:33
#7
diandianlian2007-10-19 21:34

是那个查询里的cin>>name2!

#8
ly57712007-10-20 12:28
晕忽的
#9
枫之恋2007-10-20 12:42
看不懂哦,调用了那么多函数库!
#10
tracy君帝2007-10-20 12:51
#11
willever2007-10-20 13:32
#12
iniyasha2007-10-20 13:49
          救命!!
#13
jiangbh12102007-10-20 15:25
#14
火炫龙2007-10-24 20:21
有点晕
#15
mikylen2007-10-24 20:27
#16
zj519912007-10-24 20:31
#17
liux9452007-10-24 20:34
恩看了~ 不会...
#18
mischa2007-10-24 20:35

好牛比的代码。。。

#19
garasmc2007-10-24 20:35
111111111111111111111111111111111111111
#20
navigator2007-10-24 23:52
呵呵,看不懂。
#21
zx26100092007-10-25 12:19
杂子输中文哦
#22
petroe2007-10-25 14:15
.............
#23
q3637425332007-10-25 14:37
#24
penjew2007-10-25 15:41
[IMG]http://bbs.bc-cn.net/Skins/Default/emot/em06.gif[/IMG]
#25
penjew2007-10-25 15:41
[IMG]http://bbs.bc-cn.net/Skins/Default/emot/em06.gif[/IMG]
#26
小孩不喝酒2007-10-25 16:34
貌似是很恶心

#27
nhjnhjj2007-10-25 17:03
C++
1