演示版本
VS2012
- fdopen()函数
fdopen()函数用于将流与文件句柄连接。stdio.h中的函数fopen()、fclose()、fscanf()和fprintf()是高级文件操作方式----以流的方式操作文件,fdopen()可以连接文件句柄和流。
语法
FILE *fdopen(int handle, char *type);
fdopen()函数的语法参数说明如下:
参数handle为要操作的句柄。
参数type指定流打开的方式。
fdopen()函数返回指向该流的文件指针。
示例
本示例演示用fdopen()函数连接文件句柄和流,以流的方式向文件中输入一行字符串。
其具体代码如下:
#include <stdio.h> #include <fcntl.h> #include <io.h> int main() { int hfile; FILE *fp; hfile=_open("d:\1\1\1.txt", O_RDWR+O_CREAT); fp=_fdopen(hfile, "w"); fprintf(fp, "a fei 123 english "); fclose(fp); printf("OK"); }
阿飞
2021年8月3日