Changes between Version 4 and Version 5 of RandomioExample
- Timestamp:
- 03/01/10 22:41:10 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
RandomioExample
v4 v5 9 9 *******************************************************************************/ 10 10 11 private import tango.io.protocol.Reader, 12 tango.io.protocol.Writer, 13 tango.io.FileConduit; 11 private import tango.io.device.File, 12 tango.io.stream.Data; 14 13 15 14 void main() 17 16 // open a file for reading 18 17 auto fc = new FileConduit ("random.bin", FileConduit.ReadWriteCreate); 18 19 19 scope (exit) 20 20 fc.close; 21 21 22 22 // construct (binary) reader & writer upon this conduit 23 auto read = new Reader(fc);24 auto write = new Writer(fc);23 auto output = new DataOutput(fc); 24 auto input = new DataInput(fc); 25 25 26 26 int x=10, y=20; 27 27 28 28 // write some data and flush output since IO is buffered 29 write (x) (y) (); 29 output.int32(x); 30 output.int32(y); 31 output.flush; 30 32 31 33 // rewind to file start 33 35 34 36 // read data back again, but swap destinations 35 read (y) (x); 37 y = input.int32; 38 x = input.int32; 36 39 37 40 assert (y==10);