首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QBasic -如何在QBasic中创建任何类型的文件?

QBasic -如何在QBasic中创建任何类型的文件?
EN

Stack Overflow用户
提问于 2015-08-04 02:05:05
回答 1查看 1.5K关注 0票数 1

我正在尝试通过QBasic创建批处理文件、文本文件和DLL文件。

请帮帮我。我在做一个假的DOS。

EN

回答 1

Stack Overflow用户

发布于 2015-08-04 02:42:43

这是旧的:)

如果我提醒你:

打开文件:(您可以创建、读取和写入)

代码语言:javascript
复制
Open (Path and file name) For (Mode) [Access (Type of access)] As #(File number)

其中:

(路径和文件名)-目标文件的路径和名称

(模式)-可以设置下列值之一:

代码语言:javascript
复制
  Input:  Read Mode
  Binary: Structured data
  Output: Write Mode - If the file already exist - overwrites the file.
  Append: The difference between this and Output is that if the file already exists, the content is appended to the end of the file

(访问类型)-访问类型。

代码语言:javascript
复制
  Read:  Read-Only access.
  Write: Write-Only access.
  Read Write: Available only in Append Mode

(文件号)-标识文件,就像指向该文件的指针一样。

要关闭文件,只需使用:

代码语言:javascript
复制
Close [#(FileNumber)][, #(FileNumber) ...]

是的,你可以一次关闭多个文件,如果你不指定文件号,qbasic将关闭所有打开的文件。

请注意,在追加和输出模式下,您必须先关闭文件,然后才能打开它进行读取!

好的,要读\写,使用与屏幕上相同的方法,但附加文件目标:

代码语言:javascript
复制
Input (Char Length), #(File number), (Name of the Variable)
Line Input #(File number), (Name of the Variable)
Print #(File number), (Data) [or (Binary data)] 

如果您不记得提供回车符(通常是\n),请使用ASCII char: Chr(10)

示例:

代码语言:javascript
复制
Open "c:\test.bat" for Output as #1
Print #1, "@echo off" + Chr$(10)
Print #1, "echo Hello World"
Close #1
End
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31793883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档