File I/O

Posted on 2007-08-06 01:09 谢迎飞 阅读(1055) 评论(5)  编辑 收藏 引用
前几天同事遇到一个小问题,他想编个小工具,主要用来在每个.cpp文件的开始加入一句公共的#include "",于是,感觉自己在C++这里好像也是个盲点,所以就帮忙一起想想,同时也有了一个想法就是可以借此系统的对C++和MFC,或者更多的类似问题和关于文件输入和输出的问题做个透彻的认识,同时也是想利用网络,来获得更多的事例和想法,或深刻的见解,请大家不吝赐教。
我先起个头第一期是关于CFile及其派生类
Use CFile and its derived classes for general-purpose disk I/O. Use ofstream or other Microsoft iostream classes for formatted text sent to a disk file.
It directly provides unbuffered, binary disk input/output services, and it indirectly supports text files and memory files through its derived classes.
Note that deleting the CFile object does not delete the physical file in the file system.
If you have not closed the file before destroying the object, the destructor closes it for you.
If you used new to allocate the CFile object on the heap, then you must delete it after closing the file. Close sets m_hFile to CFile::hFileNull.
So the member function Duplicate() should be use with Close() function, because of a new object which is created.
以上是个人在作例子和浏览msdn获得的一些结论,当然,除了单纯的针对本问题的关键是如何解决文件的随机读写,同时就是详细的文件输入和输出操作的结论,希望各位能够把自己遇到的关于文件输入输出操作的问题或解决方案共享出来,使我们每个人都能从中受益,同时享受技术带给我们的那份喜悦

Feedback

# re: File I/O  回复  更多评论   

2007-08-06 10:43 by pass86
<fstream>

# re: File I/O  回复  更多评论   

2007-08-07 11:48 by SmartPtr
我想这个, VS应该提供了相应的API来操作其文件,这应该是最便捷,准确的方法吧。

# re: File I/O  回复  更多评论   

2007-08-07 12:21 by pass86
@SmartPtr
不过那就没有可移植性了。

# re: File I/O  回复  更多评论   

2007-08-14 00:48 by 沐枫
其实,这个功能,VisualStudio的C++编译器已经提供了。

/FI[ ]pathname
此选项使预处理器处理指定的头文件。此选项的作用与在命令行上、CL 环境变量中或命令文件中指定源文件,并同时在每个源文件的第一行上的 #include 指令中用双引号指定该头文件相同。如果使用多个 /FI 选项,将按 CL 处理文件的顺序来包含这些文件。

在 Visual Studio 开发环境中设置此编译器选项

打开此项目的“属性页”对话框。有关详细信息,请参见设置 Visual C++ 项目属性。
单击“C/C++”文件夹。
单击“高级”属性页。
修改“强制包含”属性。

# re: File I/O  回复  更多评论   

2007-08-16 11:00 by jj
在source insight里直接写个脚本不就行了

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


posts - 3, comments - 7, trackbacks - 0, articles - 0

Copyright © 谢迎飞