mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
41 lines
664 B
Nim
41 lines
664 B
Nim
discard """
|
|
input: "Arne"
|
|
output: '''
|
|
Hello! What is your name?
|
|
Nice name: Arne
|
|
fs is: nil
|
|
|
|
threw exception
|
|
'''
|
|
disabled: "windows"
|
|
"""
|
|
|
|
|
|
import streams
|
|
|
|
|
|
block tstreams:
|
|
var outp = newFileStream(stdout)
|
|
var inp = newFileStream(stdin)
|
|
writeLine(outp, "Hello! What is your name?")
|
|
var line = readLine(inp)
|
|
writeLine(outp, "Nice name: " & line)
|
|
|
|
|
|
block tstreams2:
|
|
var
|
|
fs = newFileStream("amissingfile.txt")
|
|
line = ""
|
|
echo "fs is: ",repr(fs)
|
|
if not isNil(fs):
|
|
while fs.readLine(line):
|
|
echo line
|
|
fs.close()
|
|
|
|
|
|
block tstreams3:
|
|
try:
|
|
var fs = openFileStream("shouldneverexist.txt")
|
|
except IoError:
|
|
echo "threw exception"
|