注册 登录
编程论坛 VC++/MFC

关于文件使用方式疑问

bok002121 发布于 2013-01-26 21:03, 377 次点击
"r"只读  为输入数据,打开一个已存在的文本文件;不存在,则出错....成功,得到文件头指针fp;
"w"只写  为输出数据,打开一个文本文件;不存在则新建;成功,得到文件头指针fp;
(既然,得到相同的fp,那应该都可以用fread函数读出数据吧?)
"a"追加  向文本文件尾添加数据....不存在,则出错...成功,得到文件末尾指针(是不是空指针?)
"r+"读写 为读写打开一个文本文件,已有
"w+"读写 为读写创建一个文本文件,已有则删除后新建
"a+"读写 为读写打开一个文本文件,位置指针移到文件末尾
("r+","a+"用链表的话,似乎差不多)

4 回复
#2
yuccn2013-01-26 21:25
msdn有比较详细的解析,可以到微软官网去查下
#3
yuccn2013-01-26 21:27
http://msdn. character string mode specifies the kind of access that is requested for the file, as follows.


"r"
Opens for reading. If the file does not exist or cannot be found, the fopen call fails.
"w"
Opens an empty file for writing. If the given file exists, its contents are destroyed.
"a"
Opens for writing at the end of the file (appending) without removing the end-of-file (EOF) marker before new data is written to the file. Creates the file if it does not exist.
"r+"
Opens for both reading and writing. The file must exist.
"w+"
Opens an empty file for both reading and writing. If the file exists, its contents are destroyed.
"a+"
Opens for reading and appending. The appending operation includes the removal of the EOF marker before new data is written to the file. The EOF marker is not restored after writing is complete. Creates the file if it does not exist.
得到文件末尾指针 不是说空指针
#4
bok0021212013-01-26 22:48
回复 3楼 yuccn
谢谢
#5
bok0021212013-01-27 11:00
回复 3楼 yuccn
再请问下,比如,我用fp=fopen("i:\\book","r+");
q=fp;
然后,我对q所指得内容进行修改,那么....原文件的内容会被改变吗?
1