Debian Codegraph @

examples/io/write-byte.ck

raw
1 //---------------------------------------------------------------------
2 // name: write-byte.ck
3 // desc: example of writing bytes in BINARY mode
4 //---------------------------------------------------------------------
5 // filename
6 "write-byte.txt" => string filename;
7 // instantiate a file IO object
8 FileIO fout;
9 // open for write (in BINARY mode)
10 fout.open( filename, FileIO.WRITE | FileIO.BINARY );
11
12 // test
13 if( !fout.good() )
14 {
15 cherr <= "can't open file for writing..." <= IO.newline();
16 me.exit();
17 }
18
19 // byte sequence to write; equivalent to:
20 // abc\n123\n
21 [97, 98, 99, 10, 49, 50, 51, 10] @=> int bytes[];
22
23 // loop
24 for( int i; i < bytes.size(); i++ )
25 {
26 // write the next byte
27 // (other options include IO.INT16 and IO.INT32)
28 fout.write( bytes[i], IO.INT8 );
29 }
30
31 // close the thing
32 fout.close();
33
34 // print
35 <<< "file written:", filename >>>;