Basic fstream
fstream
是建立在 iostream
上來實作的
所以所有 iostream
的操作都可以在 fstream
上使用
舉例
由此可以知道 ifstream
是讀入,ofstream
是輸出
雖然 fstream
有自己的讀寫函數
但是 operator<<
、oeprator>>
太好用了
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
,所以用不太到然後其實 fstream
只要是"文字檔"都可以開
以下為合法操作
另外還可以開二進位檔
不過出題用不到,所以我不會
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
(紫大有)然後要注意雖然 fstream
的destructor
有關閉並處存檔案
但是還是要記得用 .close()
養成習慣在檔案用不到時關閉
可以避免檔案開起衝突
最後通常因為看這個是為了出題
所以我也放上出題的模板
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
最後按照慣例
revcoding