tstreams.nim 664 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. discard """
  2. input: "Arne"
  3. output: '''
  4. Hello! What is your name?
  5. Nice name: Arne
  6. fs is: nil
  7. threw exception
  8. '''
  9. disabled: "windows"
  10. """
  11. import streams
  12. block tstreams:
  13. var outp = newFileStream(stdout)
  14. var inp = newFileStream(stdin)
  15. writeLine(outp, "Hello! What is your name?")
  16. var line = readLine(inp)
  17. writeLine(outp, "Nice name: " & line)
  18. block tstreams2:
  19. var
  20. fs = newFileStream("amissingfile.txt")
  21. line = ""
  22. echo "fs is: ",repr(fs)
  23. if not isNil(fs):
  24. while fs.readLine(line):
  25. echo line
  26. fs.close()
  27. block tstreams3:
  28. try:
  29. var fs = openFileStream("shouldneverexist.txt")
  30. except IoError:
  31. echo "threw exception"