r/w binary

Joel Christensen joelcnz at gmail.com
Tue Jun 28 15:07:13 PDT 2011


I want to save and load levels for my game. The std.stream module 
doesn't have much examples.

Here is my code:
void saveLevel( string fileName ) {
	auto bfile = new std.stream.File;

	int ver = 1;
	string verStr = "version:";
	with( bfile ) {
		scope( exit )
			close;
		create( fileName );
		write( verStr ); write( ver ); // version
	}

	int ver2;
	char[] verStr2;
	auto bfile2 = new std.stream.File;
	with( bfile2 ) {
		scope( exit )
			close;
		create( fileName );
		read( verStr2 ); read( ver2 ); // version
	}
	writeln( verStr, ver );
}

And this is the result:
std.stream.ReadException at std\stream.d(46): Stream is not readable

- Joel


More information about the Digitalmars-d-learn mailing list