描述
打开指定的文件并返回一个TextStream对象可以用来读?慈?或追加到文件.
FreeBASIC 语法
FUNCTION OpenUnicode ( _ BYREF cwsFileName AS CWSTR, _ BYVAL IOMode AS LONG = 1, _ BYVAL bCreate AS BOOLEAN = FALSE : ) AS HRESULT |
参数
cwsFileName |
CWSTR.标识文件打开的字符串表达式.n. |
IOMode |
LONG.可三个常数:IOMode_ForReading,IOMode_ForWriting,或IOMode_ForAppending. |
bCreate |
Boolean指示一个新的文件可如果指定的文件名不存在了.价值是True如果创建一个新的文件,False如果不是创造.如果省略,则不会创建新文件. |
返回值
一个HRESULT代码.
设置
The IOMode argument can have any of the following settings:
Constant |
Value |
描述 |
IOMode_ForReading |
1 |
打开只读文件.你不能写这个文件. |
IOMode_ForWriting |
2 |
打开文件写入. |
IOMode_ForAppending |
8 |
打开文件并写入文件的结尾. |
引用文件
CTextStream.inc
示例
#include "windows.bi"
#include "Afx/AfxScrRun.bi"
#include "Afx/CTextStream.inc"
using Afx
' // Create an instance of the CTextStream class
DIM pTxtStm AS CTextStream
' // Open file as a text stream
DIM cwsFile AS CWSTR = ExePath & "\Test.txt"
pTxtStm.OpenUnicode(cwsFile, IOMode_ForReading)
' // Read the file sequentially
DO
' // Ext if we are at the end of the stream
IF pTxtStm.EOS THEN EXIT DO
' // Current line
DIM curLine AS LONG = pTxtStm.Line
' // Skip the 3rd line
IF curLine = 3 THEN
pTxtStm.SkipLine
curLine + = 1
END IF
' // Skip 10 characters
pTxtStm.Skip 10
' // Current column
DIM curColumn AS LONG = pTxtStm.Column
' // Read 5 characters
DIM cwsText AS CWSTR = pTxtStm.Read(5)
' // Skip the rest of the line
pTxtStm.SkipLine
PRINT "Line " + WSTR(curLine) + ", Column " + WSTR(curColumn) & ": " + cwsText
LOOP
PRINT "Press any key..."
SLEEP