导航:  CTextStream Class >

Create

上一页返回章节概述下一页

描述

 

创建一个指定的文件名并返回一个TextStream对象可以用来读取或写入文件.

 

FreeBASIC 语法

 

FUNCTION Create ( _

   BYREF cwsFileName AS CWSTR, _

   BYVAL bOverwrite AS BOOLEAN = TRUE, _

   BYVAL bUnicode AS BOOLEAN = FALSE _

) AS HRESULT

 

参数

cwsFileName

CWSTR.标识要创建文件的字符串表达式.

bOverwrite

Boolean值指示是否可以覆盖现有文件.价值是true如果文件可以被覆盖,false如果不能被覆盖.如果省略,现有文件不覆盖.

bUnicode

Boolean指示文件创建为一个Unicode或ASCII文件.价值是true如果文件创建为一个Unicode文件,false如果它是创造了一个ASCII文件.如果省略,一个ASCII文件假定.

 

返回值

 

一个HRESULT代码

 

引用文件

 

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

 

' // Create a text stream

DIM cwsFile AS CWSTR = ExePath & "\Test.txt"

pTxtStm.Create(cwsFile, TRUE)

 

' // Write a string and an end of line to the stream

pTxtStm.WriteLine "This is a test."

 

' // Write more strings

pTxtStm.WriteLine "This is a string."

pTxtStm.WriteLine "This is a second string."

pTxtStm.WriteLine "This is the end line."

 

PRINT

PRINT "Press any key..."

SLEEP