Posted on 2007-08-06 01:09
謝迎飛 閱讀(1114)
評論(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獲得的一些結論,當然,除了單純的針對本問題的關鍵是如何解決文件的隨機讀寫,同時就是詳細的文件輸入和輸出操作的結論,希望各位能夠把自己遇到的關于文件輸入輸出操作的問題或解決方案共享出來,使我們每個人都能從中受益,同時享受技術帶給我們的那份喜悅