c语言-文件操作(小试)
简单尝试
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *pWriter = fopen("hello.txt", "w"); //打开或新建hello.txt
if (pWriter == NULL)
{
printf("创建或打开文件失败!");
return 0;
}
fputs("hello world!", pWriter); //在pWriter文件流写入内容"hello world!"
fclose(pWriter); //关闭文件,从缓冲区将内容写入到文件中
system("pause");
return 0;
}fopen的几种模式
| 文件的使用方式 | 含义 |
| r/rb(只读) | 为输入打开一个文本或二进制文件 |
| w/wb(只写) | 为输出打开或新建一个文本或二进制文件 |
| a/ab(追加) | 在文本或二进制文件尾部追加数据 |
| r+/rb+(读写) | 在读或写打开一个文本或二进制文件 |
| w+/wb+(读写) | 在读或写新建一个文本或二进制文件 |
| a+/ab+(读写) | 读或写 打开或新建一个文本或二进制文件 |
秋风
2016-07-07