當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


haskell hLookAhead用法及代碼示例

Haskell語言IO模塊中函數hLookAhead的用法及代碼示例。

用法類型:

Handle -> IO Char

hLookAheadhdl從句柄hdl返回下一個字符,而不將其從輸入緩衝區中刪除,直到一個字符可用為止,它一直阻塞

示例1:

文件:/tmp/foo.txt
 : 

Hello, world!
How do you do?
源碼:

import IO

main = do x <- openFile "/tmp/foo.txt" ReadMode
	  y <- hLookAhead x
          putChar y
          y <- hLookAhead x
          putChar y
          y <- hGetChar x
          putChar y
          y <- hLookAhead x
          putChar y

輸出:
HHHe
         

注:本文由純淨天空篩選整理自 haskell hLookAhead。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。