| 1 |
// example showing auto-naming for file writing |
| 2 |
|
| 3 |
// instantiate a file IO object |
| 4 |
FileIO fout; |
| 5 |
|
| 6 |
// optional: set prefix and extension |
| 7 |
// (defaults prefix: "chuck-file" ext: "txt") |
| 8 |
fout.autoPrefixExtension( "chuck-file", "txt" ); |
| 9 |
|
| 10 |
// open for write (default mode: ASCII) |
| 11 |
fout.open( "special:auto", FileIO.WRITE ); |
| 12 |
|
| 13 |
// test |
| 14 |
if( !fout.good() ) |
| 15 |
{ |
| 16 |
cherr <= "can't open file for writing..." <= IO.newline(); |
| 17 |
me.exit(); |
| 18 |
} |
| 19 |
|
| 20 |
// write some stuff |
| 21 |
fout <= 1 <= " " <= 2 <= " " <= "foo" <= IO.newline(); |
| 22 |
|
| 23 |
// print the file that was written |
| 24 |
// FYI before we close it as that clears the filename |
| 25 |
<<< "file written:", fout.filename() >>>; |
| 26 |
|
| 27 |
// close the thing |
| 28 |
fout.close(); |