Skip to main content
gamedev.net
🔒 Locked

ofstream problem

Started by Zoomby 1 reply 550+ views
Original Post
Zoomby
Zoomby
hi! When I allocate an ofstream object on the freestore, I get a 0kb file when I try to write. Look at the code below. This creates an empty (0kb big) file. When I create a local instance of ofstream it works. Does anyone know the problem?
  
int main()
{ 
	ofstream* fout;
	fout=new ofstream;
	fout->open("test.txt",ios::binary);
	int number = 30;
	fout->write((char *)(&number), sizeof(number));
	return 0;
}
  
bye chris
Gabriel Fleseriu
Gabriel Fleseriu
delete fout before returning, so it flushes its buffer (and to avoid the memory leak)

Forever trusting who we are
And nothing else matters
- Metallica


[edited by - Gabriel Fleseriu on May 20, 2003 10:41:48 AM]
Forever trusting who we areAnd nothing else matters - Metallica
Zoomby
Zoomby
Thanks, that''s it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.