fopen

来自cppreference.com
< c‎ | io

定义于头文件 <stdio.h>
FILE *fopen( const char *filename, const char *mode );
表示filename打开一个文件,并返回一个文件流关联的文件。 mode用于确定文件访问模式.
原文:
Opens a file indicated by filename and returns a file stream associated with that file. mode is used to determine the file access mode.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

目录

[编辑] 参数

filename -
文件名称相关联的文件流
原文:
file name to associate the file stream to
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
mode -
空字符结尾的字符串,确定文件的访问模式
File access
mode string
Meaning Explanation Action if file
already exists
Action if file
does not exist
"r" read Open a file for reading read from start failure to open
"w" write Create a file for writing destroy contents create new
"a" append Append to a file write to end create new
"r+" read extended Open a file for read/write read from start error
"w+" write extended Create a file for read/write destroy contents create new
"a+" append extended Open a file for read/write write to end create new
File access mode flag "b" can optionally be specified to open a file in binary mode. This flag has effect only on Windows systems.
On the append file access modes, data is written to the end of the file regardless of the current position of the file position indicator.
原文:
null-terminated character string determining file access mode
File access
mode string
Meaning Explanation Action if file
already exists
Action if file
does not exist
"r" read Open a file for reading read from start failure to open
"w" write Create a file for writing destroy contents create new
"a" append Append to a file write to end create new
"r+" read extended Open a file for read/write read from start error
"w+" write extended Create a file for read/write destroy contents create new
"a+" append extended Open a file for read/write write to end create new
File access mode flag "b" can optionally be specified to open a file in binary mode. This flag has effect only on Windows systems.
On the append file access modes, data is written to the end of the file regardless of the current position of the file position indicator.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 返回值

打开的文件流上的成功,失败的NULL
原文:
Opened file stream on success, NULL on failure
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里


[编辑] 示例

#include <stdio.h>
int main()
{
    FILE *fp;
    fp = fopen("test.txt", "r");
    if (fp != NULL){
    	printf("succeed!");
        fclose(fp);
    }
    else
    	printf("fail!");
 
    return 0;
}



[编辑] 另请参阅

关闭文件
(函数) [edit]
将输出流与实际文件同步
(函数) [edit]
以不同名称打开既存的文件流
(函数) [edit]
fopenC++文档