by chrisx16x2008 on Sun Apr 12, 2009 11:16 pm ([msg=21668]see writing to a file?[/msg])
i am trying to write test to a file im using ofstream outfile ("thefile.txt", ios::app && ios::out | ios::in); outfile.open("thefile.txt"); outfile << "a"; outfile.close();
i get no compile errors at all when i type cout << it works fine but i can never get it to put "a'" into a file. i have been trying at this for 2 days someone please help me out.
by mischief on Mon Apr 13, 2009 2:59 am ([msg=21683]see Re: writing to a file?[/msg])
you're opening the file twice, once in the constructor and once with the ofstream::open member. try fixing that
The whole secret of existence is to have no fear. Never fear what will become of you, depend on no one. Only the moment you reject all help are you freed. --Buddha
by chrisx16x2008 on Mon Apr 13, 2009 11:25 pm ([msg=21746]see Re: writing to a file?[/msg])
ok so my new code. it writes to the file but everytime it opens it dumps the files. I was told a while back that ios::app was supposed to stop that by appended the contents to the new contents. Although as of right now its dumping the contents upon open.
by mischief on Tue Apr 14, 2009 12:53 am ([msg=21749]see Re: writing to a file?[/msg])
i think you have a problem with your flags. i don't think using bitwise AND is the proper way to set the flags, as far as i know only bitwise OR is supposed to work.
also, why are you using ios::in on an output stream?
The whole secret of existence is to have no fear. Never fear what will become of you, depend on no one. Only the moment you reject all help are you freed. --Buddha
The whole secret of existence is to have no fear. Never fear what will become of you, depend on no one. Only the moment you reject all help are you freed. --Buddha