Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File doesn't close properly w/ fstream command.

Status
Not open for further replies.

bishop74

Programmer
Dec 11, 2001
3
US
I have been trying to fstream an .htm file from one program to another. I copy the function perfectly from one file to another, but the new file will not work unless I open it up in notepad and save the file. Has anyone seen this before? Shouldn't the file save itself after the

outFilez.close();

function? I wil post the script if need be, but it is pretty ugly. Let me know if that will help.

Plz help. Thanks,
Dave
 
Have you flushed the buffer? Close should flush it but anything can happen.
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Don't know what ya mean Gene. How do you flush the buffer?
 
Suppose the your fstream is named "MyFileStream." Your output could look like:
Code:
MyFileStream << Something;
where &quot;Something&quot; is whatever you are outputting to the file. If &quot;MyFileStram&quot; was a text or ascii file, you could add endl to the stream because that not only adds a CR/NL to the file but also flushes the buffer.

Since you are outputting a binary file, you don't want to add any CR/NL feeds to the file, so you simply add
Code:
 MyFileStream << flush;
before closing the file. Note: you could also do
Code:
MyFileStream << Something << flush;
, too. James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Actually, I am outputting a text file... its html. The endl worked, but it looks ugly now when I view the html file because I have it do an endl everytime it encounters a space. Is there another command to get it to empty it's buffer with out any file manipulation like that?

Thanks in advance,
Dave
 
Have you tried the flush without the endl?
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top