归档问题! [英] Filing problem!

查看:54
本文介绍了归档问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Borland c ++ 5中俱乐部计划的主要功能;

我的俱乐部计划中有一个电影课...

但我有一个问题有了它:每当我通过addfilm函数添加一部电影

到film.dat文件,我删除之前添加的数据(对象),以及

一个对象可用于每次。而且我不能添加多部电影,

,因为之前的电影对象已删除。

请帮助我。


// ********************************************** 1 .addfilm ***

void addfilm()

{

film film1;

film1.setstate(1 );;
ofstream fp(" film.dat",ios :: binary);

if(!fp){

cout< <"无法打开文件。"<< endl;

system(" PAUSE");

exit(0); }

cout<< endl;

film1.puttitle();

film1.setid();

cout<<"输入艺术家:" ;;

cin>> film1.artists;

cout<<"输入Director:" ;;

cin>> film1.director;

cout<<"输入公司:" ;;

cin>> film1.company ;

cout<<"输入制作人:" ;;

cin>> film1.producer;

cout<< endl ;


fp.seekp(sizeof(类电影)* film1.getid(),ios :: beg);

fp.write((char * )& film1,sizeof(class film));

fp.close(); }

It''s a main function of club program in Borland c++ 5;
There is a film class in my club program...
But I have a problem with it: whenever I add a film by addfilm function
to film.dat file, data(objects) that I add before remove, and there is
an object available at per time. And I can''t add more than one film,
because the previous film object remove.
Please help me.

//********************************************** 1.addfilm ***
void addfilm()
{
film film1;
film1.setstate(1);
ofstream fp("film.dat", ios::binary);
if(!fp) {
cout<<"Cannot open file."<<endl;
system("PAUSE");
exit(0); }
cout<<endl;
film1.puttitle();
film1.setid();
cout<<"Enter Artists: ";
cin>>film1.artists;
cout<<"Enter Director: ";
cin>>film1.director;
cout<<"Enter Company: ";
cin>>film1.company;
cout<<"Enter Producer: ";
cin>>film1.producer;
cout<<endl;

fp.seekp(sizeof(class film)*film1.getid(), ios::beg);
fp.write((char*)&film1, sizeof(class film));
fp.close(); }

推荐答案

Ebi写道:
这是Borland c ++ 5俱乐部计划的主要功能;
我的俱乐部计划中有一个电影课...
但我有一个问题:每当我通过addfilm函数添加一个电影
到film.dat文件,数据(对象) )我在删除之前添加,并且每次都有一个对象可用。而且我不能添加多部电影,因为之前的电影对象已删除。
请帮帮我。

// ********* ************************************* 1.addfilm ***
void addfilm( )
{
电影电影1;
电影1.setstate(1);
ofstream fp(" film.dat",ios :: binary);
if( !fp){
cout<<"无法打开文件。<< endl;
系统(PAUSE);
exit(0); }
cout<< endl;
film1.puttitle();
film1.setid();


''setid''到底是什么?

cout<<"输入艺术家:" ;;
cin>> film1。艺术家;
cout<<"输入导演:" ;;
cin>> film1.director;
cout<<"输入公司:" ;;
cin>> film1.company;
cout<<"输入制作人:" ;;
cin>> film1.producer;
cout<< endl;

fp.seekp(sizeof(类电影)* film1.getid(),ios :: beg);


这取决于''getid()''。如果''getid()''总是返回0,你

将总是倒回到开头并写入第一个

已保存。

fp.write((char *)& film1,sizeof(class film));
fp.close(); }
It''s a main function of club program in Borland c++ 5;
There is a film class in my club program...
But I have a problem with it: whenever I add a film by addfilm function
to film.dat file, data(objects) that I add before remove, and there is
an object available at per time. And I can''t add more than one film,
because the previous film object remove.
Please help me.

//********************************************** 1.addfilm ***
void addfilm()
{
film film1;
film1.setstate(1);
ofstream fp("film.dat", ios::binary);
if(!fp) {
cout<<"Cannot open file."<<endl;
system("PAUSE");
exit(0); }
cout<<endl;
film1.puttitle();
film1.setid();
''setid'' to what?
cout<<"Enter Artists: ";
cin>>film1.artists;
cout<<"Enter Director: ";
cin>>film1.director;
cout<<"Enter Company: ";
cin>>film1.company;
cout<<"Enter Producer: ";
cin>>film1.producer;
cout<<endl;

fp.seekp(sizeof(class film)*film1.getid(), ios::beg);
This is dependent on ''getid()''. If ''getid()'' always returns 0, you
will always rewind to the beginning and write over the very first one
saved.
fp.write((char*)&film1, sizeof(class film));
fp.close(); }




V



V


void setid()

{

int a;

cout<<""电影的区别ID:" ;;

cin>> a;

id = a;

}

int getid(){return id;}


这些函数在电影课上,得到电影的ID和保存对象



fp.seekp(sizeof(类电影)* film1.getid(),ios :: beg);

fp.write((char *)& film1,sizeof(类电影));


每次输入id为1,2和3,所以getid()应该返回

这些值,而不是0!

您如何看待它?

帮助我。

void setid()
{
int a;
cout<<"Difine id of film:";
cin>>a;
id=a;
}
int getid() {return id;}

these functions in film class, get the id of film and save the object
at
fp.seekp(sizeof(class film)*film1.getid(), ios::beg);
fp.write((char*)&film1, sizeof(class film));

I enter 1, 2 and 3 for id every time, and so getid() should return
these value, not 0 !
what do you think about it?
Help me.


" Ebi" < KH ***** @ gmail.com>写了......
"Ebi" <kh*****@gmail.com> wrote...
void setid()
{
int a;
cout<<<"电影的区别ID:" ;;
cin>> a;
id = a;
}
int getid(){return id;}

这些函数在电影类中,得到的id拍摄并保存对象
fp.seekp(sizeof(类电影)* film1.getid(),ios :: beg);
fp.write((char *)& film1,sizeof(类电影));

我每次都输入1,2和3作为id,所以getid()应该返回
这些值,而不是0!


应该。可以?你的''电影'课程的定义是什么?

你怎么看待它?


我认为你需要调试你的程序。

帮助我。
void setid()
{
int a;
cout<<"Difine id of film:";
cin>>a;
id=a;
}
int getid() {return id;}

these functions in film class, get the id of film and save the object
at
fp.seekp(sizeof(class film)*film1.getid(), ios::beg);
fp.write((char*)&film1, sizeof(class film));

I enter 1, 2 and 3 for id every time, and so getid() should return
these value, not 0 !
Should. Does it? What''s the definition of your ''film'' class?
what do you think about it?
I think you need to debug your program.
Help me.




特别要求问题。


V



Ask particular questions.

V


这篇关于归档问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆