Skip to content

WINPUT()


从控制台或文件读取若干宽字符

语法

vb
declare function Winput( byval num as integer ) as wstring
declare function Winput( byval num as integer, byval filenum as long = 0 ) as wstring

用法

result = Winput( num [, [#]filenum } )

参数

num

要读取的字符数。

filenum

绑定文件或设备的文件编号。

返回值

返回所读取字符的 Wstring

说明

从控制台或由 filenum 指定的绑定文件/设备读取若干宽字符。

第一个版本等待并从键盘缓冲区读取 n 个宽字符。不读取扩展键。字符不回显到屏幕上。

第二个版本等待并从文件或设备读取 n 个宽字符。文件位置会被更新。

  • 注意:FreeBASIC 目前不支持从控制台读取宽字符。

注意:使用 Winput() 专用于 Input 访问文件模式,但在 Binary/Random 访问文件模式中也允许使用,但对 num 的值有一些限制(对于 random 模式,num 必须等于 OPEN 语句中 LEN 子句(或隐式值)设置的记录长度)。

示例

start GeSHi

vb
Dim char As WString * 2

Dim filename As String, enc As String
Dim f As Long

Line Input "Please enter a file name: ", filename
Line Input "Please enter an encoding type (optional): ", enc
If enc = "" Then enc = "ascii"

f = FreeFile
If Open(filename For Input Encoding enc As #f) = 0 Then
   
    Print "Press space to read a character from the file, or escape to exit."
   
    Do
       
        Select Case Input(1)
       
        Case " " 'Space
           
            If EOF(f) Then
               
                Print "You have reached the end of the file."
                Exit Do
               
            End If
           
            char = WInput(1, f)
            Print char & " (char no " & Asc(char) & ")"
           
        Case Chr(27) 'Escape
           
            Exit Do
           
        End Select
       
    Loop
   
    Close #f
   
Else
   
    Print "There was an error opening the file."
   
End If

end GeSHi

方言差异

与QB的区别

  • QB 不支持 Unicode

参见

  • Input()
  • Open

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系