Debian Codegraph @

src/test/03-Modules/08-write-read-op.ck

raw
1 // filename
2 me.dir() + "08-write-read-op.txt" => string filename;
3 // instantiate a file IO object
4 FileIO fout;
5 // open for write (default mode: ASCII)
6 fout.open( filename, FileIO.WRITE );
7 // test
8 if( !fout.good() )
9 {
10 cherr <= "can't open file for writing..." <= IO.newline();
11 me.exit();
12 }
13 // write some stuff
14 fout <= 1 <= " " <= 2 <= " " <= "foo" <= IO.newline();
15 // close the thing
16 fout.close();
17
18 // instantiate a file IO object
19 FileIO fin;
20 // open for read (default mode: ASCII)
21 fin.open( filename, FileIO.READ );
22 // test
23 if( !fin.good() )
24 {
25 cherr <= "can't open file for reading..." <= IO.newline();
26 me.exit();
27 }
28 // read in
29 fin => int x => int y => string z;
30 // close the thing
31 fin.close();
32
33 // verify
34 if( x == 1 && y == 2 && z == "foo" )
35 <<< "success" >>>;