Posted on 2007-08-06 01:09
謝迎飛 閱讀(1114)
評(píng)論(5) 編輯 收藏 引用
前幾天同事遇到一個(gè)小問題,他想編個(gè)小工具,主要用來(lái)在每個(gè).cpp文件的開始加入一句公共的#include "",于是,感覺自己在C++這里好像也是個(gè)盲點(diǎn),所以就幫忙一起想想,同時(shí)也有了一個(gè)想法就是可以借此系統(tǒng)的對(duì)C++和MFC,或者更多的類似問題和關(guān)于文件輸入和輸出的問題做個(gè)透徹的認(rèn)識(shí),同時(shí)也是想利用網(wǎng)絡(luò),來(lái)獲得更多的事例和想法,或深刻的見解,請(qǐng)大家不吝賜教。
我先起個(gè)頭第一期是關(guān)于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.
以上是個(gè)人在作例子和瀏覽msdn獲得的一些結(jié)論,當(dāng)然,除了單純的針對(duì)本問題的關(guān)鍵是如何解決文件的隨機(jī)讀寫,同時(shí)就是詳細(xì)的文件輸入和輸出操作的結(jié)論,希望各位能夠把自己遇到的關(guān)于文件輸入輸出操作的問題或解決方案共享出來(lái),使我們每個(gè)人都能從中受益,同時(shí)享受技術(shù)帶給我們的那份喜悅