Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Leda > Re: Filing prob...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 189 of 212
Post > Topic >>

Re: Filing problem!

by hall <XandreashX@[EMAIL PROTECTED] > Feb 9, 2005 at 05:49 PM

Ebi wrote:
> 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);

Here is your problem. You are opening the file in the default ios:trunc 
mode, which destroys the content of the file you just opened. try using

ofstream fp("film.dat", ios::binary | ios::app);

Any output you make to fp will be appended to the end of the file 
(unless you use seekp()...)


> 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(); }
> 


-- 
Det är bara töntar som har en .sig

( - Remove capital X from email to reply - )
 




 2 Posts in Topic:
Filing problem!
"Ebi" <khade  2005-02-02 17:03:41 
Re: Filing problem!
hall <XandreashX@[EMAI  2005-02-09 17:49:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:37:15 CDT 2008.