| 1 |
//--------------------------------------------------------------------- |
| 2 |
// name: read-line.ck |
| 3 |
// desc: basic example of reading a line of text using FileIO |
| 4 |
//--------------------------------------------------------------------- |
| 5 |
|
| 6 |
// default file |
| 7 |
me.dir() + "read-line.txt" => string filename; |
| 8 |
|
| 9 |
// look at command line |
| 10 |
if( me.args() > 0 ) me.arg(0) => filename; |
| 11 |
|
| 12 |
// instantiate |
| 13 |
FileIO fio; |
| 14 |
|
| 15 |
// open a file |
| 16 |
fio.open( filename, FileIO.READ ); |
| 17 |
|
| 18 |
// ensure it's ok |
| 19 |
if( !fio.good() ) |
| 20 |
{ |
| 21 |
cherr <= "can't open file: " <= filename <= " for reading..." |
| 22 |
<= IO.newline(); |
| 23 |
me.exit(); |
| 24 |
} |
| 25 |
|
| 26 |
// loop until end |
| 27 |
while( fio.more() ) |
| 28 |
{ |
| 29 |
chout <= fio.readLine() <= IO.newline(); |
| 30 |
} |