防水材料全国排名前20:菜鸟级题目(请问哪错了)

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 04:45:11
#include <fstream.h>
class student
{
private:
int iReg_no;
char cName[20];
public:
void setRegno()
{
cout<<"\nEnter the Registration Number:";
cin>>iReg_no;
}
void setName()
{
cout<<"\nEnter the Name of the student:";
cin>>cName;
}
int getRegno()
{
return iReg_no;
}
char *getName()
{
return cName;
}
};

int main()
{student s;
s.setRegno();
s.setName();
s.getRegno();
s.getName();

fstream fil("E:\\studfile.dat",ios::in);
fil.seekg(0,ios::end);
int iend;
iend=fil.tellg();
cout<<"the size of file is"<<iend<<endl;
cout<<"size of on record is"<<sizeof(student)<<endl;
int inorec=iend/sizeof(student);
cout<<"there are "<<inorec <<" "<<"records in the file"<<endl;
return 0;
}
这是我在C++上的一道题目我想知道它的文件大小,Enter the Registration Number:99

Enter the Name of the student:box
the size of file is 0
size of on record is24
there are 0 records in the file
Press any key to continue
它不是正确的答案
因为执行后应该有文件大小而不应该是零
记录为什么又是24呢

我到VC下面编译了一下,没有错误。编译通过,执行正常。
但是我不知道你编这个程序的目的是实现什么,所以也不知道功能是否实现了。

下面的是程序的执行过程:其中99和box是我输入的。
Enter the Registration Number:99

Enter the Name of the student:box
the size of file is0
size of on record is24
there are 0 records in the file
Press any key to continue

程序是否达到了你的目的,你自己判断吧!!

太专业了
不如问问老师和你的同学

class student ( )